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:
- Record.selectLine(options)
- Record.getCurrentSublistValue(options)
- 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.
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.
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
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.
Hi Battk,
I used the same code you shared above, but for me numberOfTransactions returned are always 0, i am fetching in dynamic mode only. I tried with multiple entities/vendors but no luck, it always returns 0. Can you please let me know what I am doing wrong.
Also, I am using the below code to create a vendor payment by applying a bill, but it works sometimes and fails sometimes.
var vendorBillPayment = recordModule.create({
type: recordModule.Type.VENDOR_PAYMENT,
isDynamic: false,
defaultValues: {
entity: vendorId
}
});
vendorBillPayment.setValue({
fieldId: 'account',
value: accountId
});
vendorBillPayment.setValue({
fieldId: 'currency',
value: currencyId
});
vendorBillPayment.setValue({
fieldId: 'exchangerate',
value: exchangeRate
});
vendorBillPayment.setValue({
fieldId: 'externalid',
value: refNum
});
vendorBillPayment.setValue({
fieldId: 'trandate',
value: txnDate
});
vendorBillPayment.setValue({
fieldId: 'tobeprinted',
value: printStatus
});
vendorBillPayment.setValue({
fieldId: 'memo',
value: description
});
for(var i=0; i < txnRequestMapJson.linkedTxns.length; i++){
var linkedTxn = txnRequestMapJson.linkedTxns[i];
vendorBillPayment.setSublistValue({
sublistId: 'apply',
fieldId: 'apply',
line: i,
value: true
});
vendorBillPayment.setSublistValue({
sublistId: 'apply',
fieldId: 'internalid',
line: i,
value: linkedTxn.txnId
});
vendorBillPayment.setSublistValue({
sublistId: 'apply',
fieldId: 'amount',
line: i,
value: linkedTxn.txnAmount
});
}
var recordId = vendorBillPayment.save({
enableSourcing: false,
ignoreMandatoryFields: true
});
When it fails it fails with the below error
{
“error”: {
“code”: “UNEXPECTED_ERROR”,
“message”: “{\”type\”:\”error.SuiteScriptError\”,\”name\”:\”UNEXPECTED_ERROR\”,\”message\”:null,\”stack\”:[\”anonymous(N/serverRecordService)\”,\”doPost(/SuiteScripts/centime_post_transactions.js:189)\”],\”cause\”:{\”type\”:\”internal error\”,\”code\”:\”UNEXPECTED_ERROR\”,\”details\”:null,\”userEvent\”:null,\”stackTrace\”:[\”anonymous(N/serverRecordService)\”,\”doPost(/SuiteScripts/centime_post_transactions.js:189)\”],\”notifyOff\”:false},\”id\”:\”b77d0131-d14d-4535-bbc2-e097c075f100-2d323032322e30342e3036\”,\”notifyOff\”:false,\”userFacing\”:false}”
}
}
It throws error at this line when I am trying to set the sublist for the first time, vendorBillPayment.setSublistValue({…..
Kindly help, Thanks in advance.