Does anyone see something wrong with this code?. I...
# suitescript
i
Does anyone see something wrong with this code?. I cant seem to get it to set the sublist value. I do get the log on the block where it is setting it but no change on the UI. This is deployed on item fulfilments
Copy code
function setData(asnInfo, context) {
    const fn = 'setData';
    log.audit({ title: fn, details: 'Start...' });
    const rec = context.newRecord;
    const lineCount = rec.getLineCount({ sublistId: 'item' });

    if (lineCount > 0) {
      for (let i = 0; i < lineCount; i += 1) {
        const itemId = rec.getSublistValue({
          sublistId: 'item',
          fieldId: 'item',
          line: i,
        });
        log.audit({ title: 'itemId', details: itemId });
        if (asnInfo[itemId]) {
          Object.keys(asnInfo[itemId]).forEach((el) => {
            if (el !== 'itemName') {
              log.audit({ title: 'setting data', details: `fieldId: ${el} - value: ${asnInfo[itemId][el]}` });
              try {
                rec.setSublistValue({
                  sublistId: 'item',
                  fieldId: el,
                  line: i,
                  value: asnInfo[itemId][el],
                });
              } catch (e) {
                log.error({ title: 'ERROR', details: e });
              }
            }
          });
        }
      }
    }
  }
b
basics are to do this beforeSubmit
you dont need
Copy code
if (lineCount > 0) {
your item fulfillment will always have at least one item line
i
Oh yeah, this is on a beforeSubmit
b
honestly, I wouldn't expect this logic to scale well, item is very bad in the uniqueness department
i
really? I just want to set some custom columns based on some information from the items
b
otherwise I recommend not being fancy and start hardcoding the fields you want to set, then move onto using asnInfo
i
oh I see what you mean!
w
Why can’t you just source the item info using source settings from your custom column field?
i
Because the value it is from the item but from a custom record, so Im looking the SO and the related custom record (asn) So I have an Item123 on the ASN Data for SO1, but that same item info can be different on another SO.
Maybe there is an easier way of doing this buit this is what I came up with 😅