I am trying to add a list item from an item record...
# suitescript
h
I am trying to add a list item from an item record to the catalog description on a sales order. When I run the script below it is giving me: "Catalogs: [object Object] | ". How can I get it to pull the Item Fields List Name (instead of ID)?
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record', 'N/search'], function(record, search) {
  
  function beforeSubmit(context) {

  if (context.type == context.UserEventType.CREATE) {


  var newRecord = context.newRecord;
  var lineCount = newRecord.getLineCount({
      sublistId: 'item'
  });
  var catalogs = [];

  for (var i = 0; i < lineCount; i++) {
      var itemId = newRecord.getSublistValue({ sublistId: 'item', fieldId: 'item', line: i });
      var itemCatalog = search.lookupFields({
        type: search.Type.ITEM,
        id: itemId,
        columns: ['custitem_catalog_field']
      }).custitem_catalog_field;

      if (itemCatalog) {
        catalogs.push(itemCatalog);
      } else {
        catalogs.push('No Catalog');
      }
    }
    
  var catalogString = 'Catalogs: ' + catalogs.join(' | ');

    newRecord.setSublistValue({
      sublistId: 'item',
      fieldId: 'item',
      line: lineCount,
      value: "2769"
    });

    newRecord.setSublistValue({
      sublistId: 'item',
      fieldId: 'amount',
      line: lineCount,
      value: 0
    });

    newRecord.setSublistValue({
      sublistId: 'item',
      fieldId: 'quantity',
      line: lineCount,
      value: 1
    });

    newRecord.setSublistValue({
      sublistId: 'item',
      fieldId: 'description',
      line: lineCount,
      value: catalogString
    });

  }
}
  
  return {
    beforeSubmit: beforeSubmit
  };
});
e
log what
itemCatalog
is returning and you'll see
👍 2
r
personally, i inspect everything before making assumptions or adding more logic
that's especially true of using a setter without know what it is you're setting