Hi, I need to perform some calculation by reading some fields from sales order on a button click that I created using before load and on button click I am calling client script function. I am facing issue to read values from fields in client script. What I am missing. Please help on this. Below is the code for client and user event both.
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record'],
function(record) {
function beforeLoad(context) {
if(context.type != context.UserEventType.VIEW) {
var newSoRecord = context.newRecord;
context.form.clientScriptFileId = 427704;
context.form.addButton({
id: "custpage_calculatecommission",
label: "Calculate Commission",
functionName: "calculatecommission()"
});
}
}
return {
beforeLoad: beforeLoad,
};
}
);
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record'],
function(record) {
function pageInit(scriptContext) {
}
function calculatecommission(scriptContext){
log.debug({title:'test',details:'test'});
var red = scriptContext.newRecord;;
var matercost = red.getValue({
fieldId:'custbody_materials_cost'
});
log.debug({title:'matercost',details:matercost});
}
return {
pageInit: pageInit,
calculatecommission: calculatecommission
};
});