Galdiator
Galdiator

Reputation: 117

How to pass parameters from suitelet to schedule script on button click: Suitescript 1.0

i have a suitelet form created in Suitescript 1.0 and it has a button. I want to pass parameters from this suitelet to a schedule script on button click.

How can I do this. Code snippet will be very helpful.

Upvotes: 1

Views: 7098

Answers (4)

Alex Brasil
Alex Brasil

Reputation: 1

This is what worked for me to create the parameters:

var params = [];
params.custscript_field1 = Field 1 Value;
params.custscript_field2 = Field 2 Value;

nlapiScheduleScript('customscript_scriptid', 'customdeploy_deployid', params);

Upvotes: 0

Mayur Savaliya
Mayur Savaliya

Reputation: 56

As you are using below code in Suitelet:

var params = { custscript_field1: 'Field 1 Value', custscript_field2: 'Field 2 Value' }; nlapiScheduleScript('customscript_scriptid', 'customdeploy_deployid', params);

Now, use this code to retrieve parameters value :

var p1 = nlapiGetContext().getSetting('SCRIPT', custscript_field1);

var p2 = nlapiGetContext().getSetting('SCRIPT', custscript_field2);

Thanks, Mayur

Upvotes: 1

Todd Grimm
Todd Grimm

Reputation: 544

Unfortunately I do not have enough reputation to simply add this as a comment. michoel's response is correct for passing parameters into your scheduled script, however the script record for your scheduled script must have these parameter fields created in order for them to be utilized. In order to create these you will need to navigate to your Scheduled Script Record (not the deployment), click on the Parameters Subtab, and then click New Parameter. This brings you to a screen much like that of creating a new custom field. You will give the field a name, an id (note that NetSuite will append custparam in front of whatever you put here), and a Type. Once that is completed you can pass parameters into these fields by referencing the script parameters internal ID. Hope that gets you going in the right direction!

Upvotes: 3

michoel
michoel

Reputation: 3783

The nlapiScheduleScript() function accepts script parameters as it's the third argument.

var params = {
  custscript_field1: 'Field 1 Value',
  custscript_field2: 'Field 2 Value',
};
nlapiScheduleScript('customscript_scriptid', 'customdeploy_deployid', params);

Note that this API is not available client side, so your button will need to call the Suitelet to trigger the Scheduled Script. Additionally, the Suitelet must run with Administrator permissions.

For further details, see the Help Center topics "SuiteScript 1.0 Creating Script Parameters (Custom Fields)" and "Scheduling APIs".

Upvotes: 3

Related Questions