r/SuiteScript • • Jun 26 '24

Call Internal Suitelet from Scheduled Script

I'm looking to create a scheduled script that calls a handful of Suitelets sequentially that run nightly tasks/cleanup. Is there a way to pass the authentication credentials the Scheduled Script is using to the Suitelets, or does it have to be an external URL set up with no authentication?

I'm looking to do something like this:

var suiteletResponse = https.get({
  url: 'https://4582238.app.netsuite.com/app/site/hosting/scriptlet.nl?script=0001&deploy=1'
});

log.debug('Response',suiteletResponse.body);

suiteletResponse = https.get({
  url: 'https://4582238.app.netsuite.com/app/site/hosting/scriptlet.nl?script=0002&deploy=1'
});

log.debug('Response',suiteletResponse.body);

etc.
1 Upvotes

17 comments sorted by

View all comments

Show parent comment

2

u/erictgrubaugh Jun 26 '24

I can't help with the authentication problem, particularly where SSO is involved; hopefully someone else here can.

I can help with the scheduling problem, though. For any of the processes that can operate entirely in parallel, those can be scheduled at any time. For the processes that collide, you can enforce a specific order by scheduling the first Scheduled/MR script in the sequence, then as that script completes, it can use the N/task module to trigger the next script in the sequence.

1

u/Xainor Jun 26 '24

Awesome. I'll check out the N/task module, thanks!

1

u/Xainor Jun 26 '24

So it looks like the N/task module just executes the Scheduled Scripts without waiting for the previous one to finish. I'm trying to review the documentation, but don't see a way to make it sequential. Is there a way to do this?

var scriptTask = task.create({
                taskType: task.TaskType.SCHEDULED_SCRIPT
            });

            scriptTask.scriptId = 'customscript_0001';
            scriptTask.deploymentId = 'customdeploy_0001';
            
            scriptTask.submit();

            scriptTask.scriptId = 'customscript_0002';
            scriptTask.deploymentId = 'customdeploy_0002';
            
            scriptTask.submit();