Sunday, September 9, 2018

Execute nlapiSetRedirectURL() from a client side script

1) Create a suitelet which contains the nlapiSetRedirectURL() function:

 function mySuitelet (request,response){
  nlapiSetRedirectURL('RECORD', 'contact', '4', true);
 }


2) Deploy the suitelet and note the script id and deployment id of the suitelet.


3) Use the ids inside a client side script which contains the client_requestSuitelet() function: 

function client_requestSuitelet()
{
   var url = nlapiResolveURL('SUITELET', 'customscript57', 'customdeploy5');
   document.location=url;
}


The above code redirects the user to a particular record type with a particular record id, both of which are hard-coded inside the suitelet. If you do not wish to hard code these values, then use the code below for a more dynamic way of passing the values to the suitelet.
 

function client_requestSuitelet()
{
   var url = nlapiResolveURL('SUITELET', 'customscript57', 'customdeploy5') + '&entity=' + nlapiGetRecordId() +  '&recordType=' + nlapiGetRecordType();
   document.location=url;
}

 

function mySuitelet (request,response)
{
  var recType = request.getParameter('recordType');
  var recId = request.getParameter('entity');
  nlapiSetRedirectURL('RECORD', recType, recId, true);
}

 

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations. NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto. NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

1 comment:

  1. Quality stuff may be the key to invite the users to visit begin to see the blog site, that’s what this site provides.
    premium corporate gifts

    ReplyDelete