Pass Parameter to Suitelet to Scheduled Script

I’m trying to pass a custom parameter from my Suitelet to my Schedule Script. The problem is that it shows me null value when I try to log.debug the paramter ID in Scheduled, but in Suitelet i can log.debug the parameter ID just fine.

I’m using NApiVersion 2.1 both Suitelet and Scheduled.

Suitelet:

var scriptTask = task.create({taskType: task.TaskType.SCHEDULED_SCRIPT,scriptId: “customscript_ss_purchase_order_pdf”,deploymentId: “customdeploy_ss_purchase_order_pdf”,params: { id: id } });var scriptTaskId = scriptTask.submit();

Scheduled:

var id2 = runtime.getCurrentScript().getParameter(“id”);var id = runtime.getCurrentScript().getParameter({name: ‘id’});

log.debug(‘id’, id);

log.debug(‘id2’, id2);

already tried:

  • runtime.getCurrentScript().getParameter({name: ‘custscript_id’});

  • runtime.getCurrentScript().getParameter(“custscript_id”);

  • changing parameter name.

  • scriptContext.request.parameters[‘id’];

Rookie Asked on May 9, 2023 in SuiteScript.
Add Comment
1 Answer(s)

Based on the code you provided, it seems like you are passing the parameter correctly from the Suitelet to the Scheduled Script. The issue may be with how you are trying to retrieve the parameter in the Scheduled Script.

In your Scheduled Script, you can try using the getParameter method with the name parameter instead of the parameter ID:

var id = runtime.getCurrentScript().getParameter({name: 'id'});

If the parameter is still null, you can try logging the entire list of parameters to see if the parameter is being passed correctly from the Suitelet:

var params = runtime.getCurrentScript().getParameters();
log.debug('params', params);

This should output a list of all the parameters passed to the Scheduled Script, including the id parameter. You can then check if the parameter is present in the list and verify its value.

If you are still having issues, you can try updating the parameter name to something more unique to avoid any naming conflicts:

var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscript_ss_purchase_order_pdf',
deploymentId: 'customdeploy_ss_purchase_order_pdf',
params: {
myParam: id // change 'id' to a unique parameter name
}
});

And in your Scheduled Script, update the getParameter method accordingly:

var myParam = runtime.getCurrentScript().getParameter
Beginner Answered on May 11, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor