Ronin
Ronin

Reputation: 11

suitescript 2.0 : How to modify and save subrecord in clientscript

I'm trying to modify and save subrecord in clientscript, but when it is saved, I get the following error:

"Cannot read property 'invalidateCurrentSublistLineForSubrecordCache' of undefined"

Current code:

/**
* @NApiVersion 2.x
* @NModuleScope public
*/
define(['N/record','N/currentRecord','N/search'],
  function(record,currentRecord,search) {
  return({
    stock: function(context) {
      var curRec = currentRecord.get();

      var ab_search = search.create({
        type: search.Type.TRANSACTION,
        title: 'YXZC_Assembly_Build_Search',
        id: 'customsearch_yxzc_assembly_build_search',
        columns: ['internalid'],
        filters: [
          ['createdfrom', 'is', curRec.id],'and',['type','is','Build']
        ]
      });
      ab_search.save();
      var searchResult = ab_search.run().getRange({
        start: 0,
        end: 1
      })[0];
      var internalid = searchResult.getValue(searchResult.columns[0]);
      search.delete({
        id: 'customsearch_yxzc_assembly_build_search'
      });
      var rec = record.load({
        type: record.Type.ASSEMBLY_BUILD,
        id: internalid,
        // isDynamic: true,
      });
      var inventorydetailRec = rec.getSubrecord({
        fieldId: 'inventorydetail',
      });
      var line = inventorydetailRec.getLineCount({
        sublistId: 'inventoryassignment'
      });
      for (var i=0; i<line; i++){
        inventorydetailRec.setSublistValue({
          sublistId:'inventoryassignment',
          fieldId: 'inventorystatus',
          line: i,
          value: '2'
        });
      };
      var recId = rec.save({
        enableSourcing: true,
        ignoreMandatoryFields: true
      });
    }
  });
});

I am not sure what invalidateCurrentSublistLineForSubrecordCache property means.

What does anyone know about why this error is occurring?

Upvotes: 1

Views: 2706

Answers (2)

Budy Sutjijati
Budy Sutjijati

Reputation: 21

Try the record.submitFields()

See https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4267283788.html

I have just stumbled upon your question since I had the same issue but found a solution by the help of @erictgrubaugh

Upvotes: 1

ehcanadian
ehcanadian

Reputation: 1784

Subrecords are read-only for client scripts. Clients scripts are able to delete a subrecord from a parent record, but they can not modify them. See Supported Deployments for Subrecord Scripting in the NetSuite help

Upvotes: 1

Related Questions