RE: Netsuite: Suitescript 2.0: Dynamic Mode Record getSublistValue/getCurrentSublistValue Isn’t Working

Overview:

I’m working on Netsuite 2019.2.

Using Suitescript 2.0, I’m requested to create a VendorPayment record.

I used the ‘N/record’ module to create vendorPayment as dynamic mode.

However, based on Suitescript documentation.

Dynamic mode: When a SuiteScript 2.0 script creates, copies, loads, or transforms a record in dynamic mode, the record’s body fields and sublist line items are sourced, calculated, and validated in real-time. A record in dynamic mode emulates the behavior of a record in the UI.”

When I create the vendor payment in UI. I get 5 transactions of a specified vendor in the “apply” list.

However, when I create the vendor payment in Suitescript using the following code:

 var billPayment = record.create({
                type: record.Type.VENDOR_PAYMENT, isDynamic: true, defaultValues: { entity: vendorPaymentModel.entity }
            });

And access the sublist “apply” line count, I got 5 transactions, as expected:

var numberOfTransactions = billPayment.getLineCount({ sublistId:'apply' });

Problem:

When I try to access the sublist transaction lines using one of the following two approaches, I get empty values.

    for (var i = 0; i < numberOfTransactions; i++) {
                    var apply = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i });
                    var internal = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i });
                    var transactionType = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'trantype', line: i });
                    var amountDue = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'refnum', line: i });
                    var paymentAmount = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'amount', line: i });
                    var transactionDate = billPayment.getSublistValue({ sublistId: 'apply', fieldId: 'applydate', line: i });
}

All of the values are empty, except the last line.

I tried to switch to use the second approach where:

  1. Record.selectLine(options)
  2. Record.getCurrentSublistValue(options)
  3. Record.commitLine(options)

But It doesn’t work either.

Please any help, would be much appreciated. If you need any other clarifications or screenshots, please let me know.

nadeemkhoury Rookie Asked on October 31, 2019 in SuiteScript.
Add Comment
1 Answers

Your code looks reasonable (outside of a weird choice of field for a variable named amountDue) and works in my account.

  
require(["N/record"], function(record) {
 var billPayment = record.create({
  type: record.Type.VENDOR_PAYMENT,
  isDynamic: true,
  defaultValues: { entity: "11" }
 });
 var numberOfTransactions = billPayment.getLineCount({ sublistId: "apply" });
 for (var i = 0; i < numberOfTransactions; i++) {
  var apply = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "apply",
   line: i
  });
  var internal = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "internalid",
   line: i
  });
  var transactionType = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "trantype",
   line: i
  });
  var amountDue = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "due",
   line: i
  });
  var paymentAmount = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "amount",
   line: i
  });
  var transactionDate = billPayment.getSublistValue({
   sublistId: "apply",
   fieldId: "applydate",
   line: i
  });
  var values = {
   apply: apply,
   internal: internal,
   transactionType: transactionType,
   amountDue: amountDue,
   paymentAmount: paymentAmount,
   transactionDate: transactionDate
  };
  typeof console !== "undefined"
   ? console.log(values)
   : log.debug("values", values);
 }
});
 

This outputs something that looks like:

{“apply”:false,”internal”:”630″,”transactionType”:”VendBill”,”amountDue”:1142,”paymentAmount”:””,”transactionDate”:”2019-08-08T07:00:00.000Z”}

paymentAmount being empty is reasonable for an unapplied line.

Beginner Answered on October 31, 2019.

Hi Battk, Thank you for you answer. I apologize for that mistake. Can you please tell me how many transaction lines did you have with that associated vendor entity? Because as I mentioned, if you have more than one line, Only the last ones outputs correctly, Others are empty. Can you please verify and let me know. Thanks

on November 1, 2019.

Had 3 lines. Other lines look like:

{ apply: false, internal: “847”, transactionType: “VendBill”, amountDue: 15, paymentAmount: “”, transactionDate: Date Fri Nov 01 2019 00:00:00 GMT-0700 (Pacific Daylight Time) }

and

{ apply: false, internal: “849”, transactionType: “VendBill”, amountDue: 20, paymentAmount: “”, transactionDate: Date Wed Oct 30 2019 00:00:00 GMT-0700 (Pacific Daylight Time) }

You can try sharing more of your code, but what you shared works fine in isolation.

on November 1, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.