Nadeem Khoury
Nadeem Khoury

Reputation: 937

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.

Upvotes: 1

Views: 2548

Answers (1)

Martha
Martha

Reputation: 764

Are you trying to get multiple sublist values? The way I'm reading your for loop suggests you expect multiple values for apply, internal, etc. But you said you're only getting 1 value instead of 5. I think this is because when for example i=1 the old value (line 0) for apply is overwritten by the new value for apply (line 1). Perhaps try using an array to store all the values for each (apply, internal, etc.).

Try:

//empty arrays to hold values
var applys = newArray();
var internals = newArray();
var transactionTypes = newArray();
var amountDues = newArray();
var paymentAmounts = newArray();
var transactionDate = new array();


for (var i = 0; i < numberOfTransactions; i++) {

//for each line get the value
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 });

//now save the current values in the array before getting the next set of values
applys.push(apply);
internals.push(internal);
transactionTypes.push(transactionType);
amountDues.push(amountDue);
paymentAmounts.push(paymentAmount);
transactionDate.push(transactionDate);

}

Later in your code, if you recall "apply" now instead you'll have to do a for loop and recall "applys[x]"

I'm new to this site, and new to working with Scripts in NetSuite but I hope this helps/works for you.

Upvotes: 0

Related Questions