Friday, September 7, 2018

Sample Suitelet with Custom Button to Call Additional Functions

Image


This sample suitelet will add a custom button that when clicked will call a function from another SuiteScript (a client script).
  
1. Create a Client Side Suitescript with the code to be executed when a button is clicked on the Suitelet form. Sample Code below:

function talert(){
  var cust_field = nlapiGetFieldValue('customerfield');
  alert('The Custom Select Field value is: '+cust_field);
}
 

2. Create a new Client Script in Netsuite by going to Customization > ScriptingScripts > New > Client. Upload the script file.

3. Get the script id (e.g. customscript101).
 
4. Create a Suitelet by going to Go to Customization > Scripting > Scripts > New > Suitelet. Script file should create the form with additional buttons. Use the setScript method and set the id of the client script. On the addButton method, indicate the function name as the script parameter. Sample code below

function buttonAlert(request, response)
{
   if ( request.getMethod() == 'GET' )
  {
    var form = nlapiCreateForm('Simple Form');
    var field=form.addField('customerfield', 'select', 'Customer', 'customer');
    form.setScript('customscript101');
    form.addButton('custpage_button','Alert', "talert();");
    response.writePage( form );
   }
}
 


5. Deploy the script.
 
Additional Illustrations below
 
Image
 
Image
 
Image

No comments:

Post a Comment