In User Event Script passing a variable as a function parameter to a referenced Client Script.
Category : NetSuite suitescript SuiteScript 2.0
Problem Statement
In this tutorial of netsuite training from your netsuite solution provider we are showing two scripts interaction with each other. There was a Customer working in the sales order customization, wants to pass a value from their User Event script to a referenced Client Script so that it can be used for further processing within the Client Script. The Client Script will be triggered by a button that was created by the User Event script on beforeLoad.
Feel free to reach out for any netsuite customization netsuite solution provider, netsuite implementation, netsuite consultation , netsuite customization, netsuite Support, netsuite Training
contact us at: Email : [email protected]
Approach
As a netsuite solution provider, we suggest for this netsuite customization, Declare A variable and store the value which will be passed as a function parameter in one of the functions of the referenced Client Script. The sample codes below will include scenarios for when passing a number, a string, or a URL parameter.
Step 1: Create a client script that will use the value to be passed and upload it to the file cabinet.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define([‘N/ui/dialog’],
function(dialog) {
function pageInit(context) {
}
function showPassedValueFunc(paramTest) {
var clientVar = paramTest
var options = {
title: “Passed Value”,
message: clientVar //Display the value using an alert dialog
};
dialog.alert(options)
}
return {
pageInit: pageInit,
showPassedValueFunc: showPassedValueFunc
};
});
Step 2: Create the User Event script that will reference the Client Script and pass the value to it. Deploy script to the intended record.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([‘N/url’],function(url) {
function beforeLoad(scriptContext) {
var userVarNum = 99
var userVarStr = ‘Sample String’;
var userVarURL = url.resolveRecord({
recordType: ‘recordIdname’
});
//Reference the previously created Client Script
thisForm = scriptContext.form;
thisForm.clientScriptFileId = FileId;
//Add a button and call the specific function from the Client Script
thisForm.addButton({
id : ‘custpage_label’,
label : ‘Label’,
functionName: ‘showPassedValueFunc(‘ + userVarNum + ‘)’ //Format when passing a number
//functionName: “showPassedValueFunc(‘” + userVarStr + “‘)” //Format when passing a string
//functionName: “showPassedValueFunc(‘” + userVarURL + “‘)” //Format when passing a URL
});
}
return {
beforeLoad: beforeLoad
};
});
Reference : netsuite.com, netsuite help and netsuite guide.
Feel free to reach out netsuite solution provider, netsuite implementation, netsuite consultation , netsuite customization, netsuite Support, netsuite Training
contact us at: Email : [email protected]
Linkedin : https://www.linkedin.com/company/netsuite-academy/