Reputation: 1
How can I make my script work? The goal is to have a custom field that will count the line items in Deposit page while on Edit mode. Please note that I am an accountant and interested in learning javascript so my script is a mess.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/currentRecord'], currentRecord => {
test_set_getValue: () => {
// Get a reference to the currently active record
let myRecord = currentRecord.get();
var numLines = objRecord.getLineCount({
sublistId: 'item'
});
// Set the value of a custom field
myRecord.setValue({
fieldId: 'custbody_ns_acs_item_count',
value: numLines
});
},
return {
beforeSubmit: beforeSubmit
};
});
Upvotes: 0
Views: 450
Reputation: 15462
It looks like your script was copied from a couple of different places.
For a bank deposit you need to use the correct sublines ids.
See the data dictionary for deposits
try:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([], () => {
function beforeSubmit(ctx){
// Get a reference to the currently active record
let myRecord = ctx.newRecord;
const subLines = (sublist)=>{
const lineCount = myRecord.getLineCount({sublistId:sublist});
return lineCount == -1 ? 0 : lineCount;
};
// Set the value of a custom field
myRecord.setValue({
fieldId: 'custbody_ns_acs_item_count',
value: subLines('cashback') + subLines('other') + subLines('deposit')
});
},
return {
beforeSubmit: beforeSubmit
};
});
Upvotes: 1