In Netsuite Customization Client script executes in the logged-in user’s role. This can create errors while trying to access records for which the logged-in user doesn’t have the required permission. The solution is to call a backend suitelet from the client script. We suggest If you need to use that value in the client script for setting values or giving alerts, then you can return the value from suitelet back to the client script. Eg: On the field change of location field in the sales order, you want to load the location record and get some values but if the logged-in user doesn’t have access to the location record, then you should not load the location record from the client script as it will throw an error due to insufficient 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 are any variable.
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);
}