Hi, I need to perform some calculation by reading ...
# suitescript
t
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 }; });
s
Firstly, your client script function has no
context
(you can tell this because you called it with a button that is passing nothing.
I would recommend just reading the value in the UE and passing to the client script, and calling the client script function.
Copy code
var matercost = rec.getValue({
				fieldId:'custbody_materials_cost'
				});
And
functionName: "calculatecommission(" + matercost + ")"
. This way you have passed the value you need to your client script and you can do whatever you want with it.
✔️ 2
b
use currentRecord.get() to access the current record in your client script
✔️ 1
t
Thankuh all ... currentRecord.get() worked
👀 1