Sunday, April 21, 2019

Schedule a script using Suitelet button

Would like to create a Suitelet and a button that will schedule a script using nlapiScheduleScript.

(1) Create your main Suitelet that will hold the button

function scheduleAScript(request, response)
{
   if ( request.getMethod() == 'GET' )
  {
    var form = nlapiCreateForm('Simple Form');
    var field=form.addField('customerfield', 'select', 'Customer', 'customer');
    form.setScript('customscript266');
    form.addButton('custpage_button','Schedule Script', "openSuitelet();");
    response.writePage( form );
  }
}

(2) Create an open script that will call the scheduling script. You may copy this below script in the same file as your Suitelet.

function openSuitelet()
{
    var url = nlapiResolveURL('SUITELET', 'customscript269', 'customdeploy1');
    window.open(url);
}

(3) Create a new Suitelet that will reschedule the script

function schedScript(){
   var result = nlapiScheduleScript(196, 1);  // 196 is internal id of the scheduled script that you wish to reschedule and 1 is deployment id
}

NOTE:

To test this, run the deployment of scheduleAScript, select the button 'Schedule Script', go to Customization > Scripting > Script Deployments > Status.

No comments:

Post a Comment