HOW TO RETURN A VALUE FROM A BACKEND SUITELET TO CLIENT SCRIPT?

HOW TO RETURN A VALUE FROM A BACKEND SUITELET TO CLIENT SCRIPT?

IN Netsuite Customization Client script executes in the logged in user’s role. This can create errors while trying to access records for which logged in user doesn’t have required permission. The solution is to call a backend suitelet from the client script.As a NetSuite Solution provider  we suggest  If you need to use that value in client script for setting values or giving alert, then you can return the value from suitelet back to client script.Eg: On field change of location field in sales order, you want to load the location record and get some values but if the logged in user doesn’t have access to location record, then you should not load the location record from client script as it will throw error due to in-sufficient permission.

You can use nlapirequesturl to call backend suitelet and from suitelet after searching the values, write it back using response.write(values) where values is any variable. See the code below for more detail fo:r netsuite support

client script:

var loc_id =  nlapiGetFieldValue(‘location’);

var suiteletUrl = nlapiResolveURL(‘SUITELET’, ‘scriptid’, ‘script deployment id’); //Get the Suitelet URL

var response = nlapiRequestURL(suiteletUrl+ ‘&loc_id=’ +loc_id);

if(response.getBody())
{
var address = response.getBody();

nlapiSetFieldValue(‘custpage_address’, address);

}

suitelet script:

var loc_id = request.getParameter(‘loc_id’);

if(loc_id)
{

var load_loc = nlapiLoadRecord(‘location’, loc_id );

var addrs = load_loc.getFieldValue(‘addrtext’);

response.write(addrs);
}

Feel free to reach out TheSmilingCoders for proper netsuite implementationnetsuite consultation , netsuite customizationnetsuite Support,netsuite Training contact us at:

Email : [email protected]

Facebook : https://www.facebook.com/Smiling-Coders-Netsuite-Training-Implementation-and-Support-1591053827660082/

Linkedin : https://www.linkedin.com/company/netsuite-academy/


Log out of this account

Leave a Reply