I thought that declaring an object outside the sco...
# suitescript
s
I thought that declaring an object outside the scope of an entry point makes it global and it retains its values to be shared between different entry points but it looks like it doesnt. How would i create an object that retains its values so that it can be used in another entry point?
define(['N/record', 'N/log', 'N/ui/dialog'], function (record, log, dialog) {
function Sublist(lines, quantities = [], names = []) {//contructor
this.lines = lines;
this.quantities = quantities;
this.names = names;
}
var initialSublist = new Sublist();//create object
var afterSublist = new Sublist();//create object
function beforeLoad(context) {
if (context.type !== context.UserEventType.EDIT) return;
var objRecord = context.newRecord;
//get initial values
return true;
}
function beforeSubmit(context) {
if (context.type !== context.UserEventType.EDIT) return;
var objRecord = context.newRecord;
//get after values
//compare initialSublist with afterSublist
}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit
}
});
when i enter beforeSubmit, its clearing the values in initialSublist
r
Use
context.oldRecord
/
context.newRecord
within an entry point function. I think that's what you're trying to do...
❤️ 1
s
yea i just found oldRecord and its what im looking for
👍🏻 1
b
the different entry points run in different contexts at different times
netsuite is not saving the context of the beforeLoad entry point to be used in the beforeSubmit, it discards the beforeLoad context after its done with it
you can only do what you were trying to do in a client script
technically you can do it in a map/reduce as well, but its not sane since the context is lost whenever the processor yields, which is not a process you control