Hello everyone,
I am currently updating to make my commission script to work after the record is submitted.
Currently, the pageinit and validateline functions, is causing delays in the system and this primarily can affect orders with a large number of items. Someone would open the record, and while working it, the script will run to calculate commissions and then push you down to the line items page.
That's the reason for changing it up. However, I constantly get the following error when searching for the line items on the record.
TypeError: Cannot read property 'getLineCount' of undefined
I am calling the variable based on whether a new order is being created, or edited
if (context.type === context.UserEventType.CREATE) { var currRecord = context.newRecord; }
if (context.type === context.UserEventType.EDIT) { var currRecord = context.Record; }
When I check the console log, there's no object for the Sales Order.
Goal:
After Submitting the record to be created or updated, get line items from record.
If I can get the record loaded, then I can do the rest.
/**
@NApiVersion 2.1
@NScriptType UserEventScript
@NModuleScope SameAccount
*/
define(['N/record','N/log'], (record,log)=>{
const UpdateSO = (context)=>{
if (context.type === context.UserEventType.DELETE) { log.debug("context.UserEventType.DELETE",true); return true; }
if (context.type === context.UserEventType.CREATE) { var currRecord = context.newRecord; }
if (context.type === context.UserEventType.EDIT) { var currRecord = context.Record; }
log.debug('currRecord',currRecord);
var lines = currRecord.getLineCount({sublistId:'line'});
var discountRate = currRecord.getValue({ fieldId: 'discountrate'});
log.debug('discount rate',discountRate);
for(let i=0; i<lines; i++){
var lineNum = currRecord.selectLine({ sublistId: 'item', line: i });
log.debug('lineNum',lineNum);
}
log.debug('success',true);
}
return {
afterSubmit : UpdateSO
};
});