-->

Netsuite SuiteScript 2.0 How to complete the param

2019-08-15 12:49发布

问题:

I am trying to call the Netsuite SuiteScript 2.0 N/record module's load function, but I am unsure as to what to pass for the parameters. Basically I would like a N/record with the same id (primary key) of the current record in the UI, that I can use to loop through the sublist items.

I'm not sure how to use the Records Browser in order to find the correct type and id. The Records Browser does not have the type, so I guessed at the name. There are also multiple fields that could be the primary key id. Is it tranid or externalid or some other field? I'm specifically interested in the Inventory Adjustment form. externalid is undefined and tranid is To Be Generated.

Is it possible to get a N/Record based on the currentRecord in this manner or will it also suffer from the same issues I have with currentRecord (I can't use selectLine to step through the sublist items, sublist items have not been saved yet and the last one is partially completed)?

/**
 * @NApiVersion 2.0
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/search', 'N/record'], function (s, r) {
   function fieldChanged(context) {
      var currentRecord = context.currentRecord;
      var sublistName = context.sublistId;
      var sublistFieldName = context.fieldId;
      var currentLine = context.line;
      var recordId = currentRecord.getValue({fieldId: "externalid"});
      var record = r.load({
         type: r.Type.INVENTORY_ADJUSTMENT,
         id: recordId,
         isDynamic: true
      });

回答1:

Is it possible to get a N/Record based on the currentRecord

Yes, although N/record module is used to load/create records. So in order to use N/record module, you need to make sure that your record already exists or you are creating new.

InternalId specified at the top of the Records Browser page is the recordType that you need to pass as type to record module.

Also try using async version of record load. i.e record.load.promise in client script.