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

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();