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

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. 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:




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);
}

For Netsuite Training (Including training for interviews), Support, Implementation contact us at:

Email : netsuiteacademy@netsuite-academy.com

Facebook page : https://www.facebook.com/Netsuite-Academy-1591053827660082/

Comments

  1. We are NetSuite Solution Provider with vast experience in NetSuite Implementation, netsuite customization including netsuite training & netsuite integration.
    NetSuite Solution Provider
    NetSuite Training
    NetSuite Implementation
    NetSuite Customization
    NetSuite Integration

    ReplyDelete

Post a Comment

Popular posts from this blog

Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite

Understand Core Technology behind SuiteScript 2.0

HOW TO SET SUBLIST SUB RECORD VALUES IN SUITE SCRIPT 1.0 AND 2.0