I'm trying to load the "from" location details for...
# suitescript
y
I'm trying to load the "from" location details for an item fulfilment. I believe this may be at the line item level (the SS loads it as "location.addressee", "location.addr1", etc.), however when I try to load the location details, those fields aren't available (the record has fields like "mainaddress_text"). I've also tried to load the "address" subrecord off of the location, but I'm not sure if that is right: "Field mainaddress is not a subrecord field."
1
b
do not assume that records and searches represent data the same way
the same data can be in different fields / columns or not present at all
location.addressee
indicates that the saved search column
addressee
is from the
location
join
that location is its own saved search with its own columns, but the join allows you to access it from a transaction search
records dont have an equivalent, each individual record must be loaded to gain access
that would mean loading the item fulfillment, getting the id of the location, then loading the matching location
subrecords are records that can only be accessed from a parent record, so you would load the parent record and then get the subrecord
in your case, the address is a subrecord found in the mainaddress field of the location record
id also be weary in general about your question, the location field of an item fulfillment has no relation to where its shipped from
y
Hey @battk - thank you for the thorough reply. Can I just double check what you mean as well by "the address is a subrecord found in the mainaddress field of the location record", when I tried that yesterday I got the error "Field mainaddress is not a subrecord field.", it only had mainaddress_text
b
what did the code look like
y
Let me grab that and pop it in here, just a moment
Sorry I think there's a better way to attach longer scripts but here is what I'm doing:
Copy code
//#region Line items
    var numLines = loadedIF.getLineCount({
      sublistId: 'item',
    });

    log.debug({
      title: 'Number of line items',
      details: numLines,
    });

    //loop through the number of line in IF
    var items = [];
    for (var i = 0; i < numLines; i++) {
      var itemInternalID = loadedIF.getSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        line: i,
      });

      var itemType = loadedIF.getSublistValue({
        sublistId: 'item',
        fieldId: 'itemtype',
        line: i,
      });

      var isKit = itemType.toLowerCase() === 'kit';
      var isInventory = itemType.toLowerCase() === 'invtpart';

      log.debug({
        title: 'Item Type',
        details: itemType,
      });

      var itemObj = null;
      if (isKit) {
        //load the item using the internal id
        itemObj = record.load({
          type: record.Type.KIT_ITEM,
          id: itemInternalID,
        });
      } else if (isInventory) {
        //load the item using the internal id
        itemObj = record.load({
          type: record.Type.INVENTORY_ITEM,
          id: itemInternalID,
        });
      }

      if (itemObj) {
        log.debug({
          title: 'Item found',
          details: 'Yes',
        });

        var item_reference = null;
        var item_description = null;
        var item_quantity = null;
        var item_cartons = null;
        var item_width = null;
        var item_length = null;
        var item_height = null;
        var item_weight = null;
        var item_lineID = null;

        var from_name = null;
        var from_phone = null;
        var from_address1 = null;
        var from_address2 = null;
        var from_suburb = null;
        var from_state = null;
        var from_postcode = null;

        // Retrieve the location ID from each line item
        var locationId = loadedIF.getSublistValue({
          sublistId: 'item',
          fieldId: 'location',
          line: i,
        });

        // Load and process location details if needed
        if (locationId) {
          var locationRecord = record.load({
            type: record.Type.LOCATION,
            id: locationId,
          });

          // Access the address subrecord
          var mainAddressSubrecord = locationRecord.getSubrecord({
            fieldId: 'mainaddress',
          });

          // Retrieve address fields
          from_name = mainAddressSubrecord.getValue({ fieldId: 'addressee' });
          from_phone = mainAddressSubrecord.getValue({ fieldId: 'phone' });
          from_address1 = mainAddressSubrecord.getValue({ fieldId: 'addr1' });
          from_address2 = mainAddressSubrecord.getValue({ fieldId: 'addr2' });
          from_suburb = mainAddressSubrecord.getValue({ fieldId: 'city' });
          from_state = mainAddressSubrecord.getValue({ fieldId: 'state' });
          from_postcode = mainAddressSubrecord.getValue({ fieldId: 'zip' });
        }

        var item = {
          from_name: from_name,
          from_phone: from_phone,
          from_address1: from_address1,
          from_address2: from_address2,
          from_suburb: from_suburb,
          from_state: from_state,
          from_postcode: from_postcode,
        };

        items.push(item);
      } else {
        log.debug({
          title: 'Item found',
          details: 'No',
        });
      }
    }

    log.debug({
      title: 'Items',
      details: JSON.stringify(items),
    });
    //#endregion
Also this is for a user event script, on create for an IF record
The issue in the above is for the "mainAddressSubrecord"
Just shortened it a bit
b
works for me
make sure it isnt a permission related issue
y
Oh, okay amazing! Let me check with the admin team, as I cannot set my own permissions, that's great to know it works!
Hey @battk do you happen to know what permissions could be needed? Apparently I have full permissions for "location" and "address list in search" (this second one was the only one my colleague could find that states info about an address)
Got it, had to clear cache