how can i check that if all deployments of the sch...
# ask-stanley-ai
n
how can i check that if all deployments of the scheduled script are utilized then i call another script ? let scheduleScriptTaskObj = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: "customscript712", deploymentId: null, //Eman Sultan params: { custscriptreques_name: invReqName, // pass the value as a script parameter custscriptreques_id:invReqID } });
c
AI generated answer (using internal Slack threads):
To check if all deployments of a scheduled script are utilized and then call another script, you can use the
search
module in SuiteScript to search for the status of the scheduled script instances. If all instances are in use, you can then call another script. Here is a sample code snippet:
Copy code
javascript
var search = require('N/search');

// Create a search on scheduled script instance
var scriptInstanceSearch = search.create({
    type: search.Type.SCHEDULED_SCRIPT_INSTANCE,
    filters: [
        ['scriptId', 'is', 'customscript712']
    ],
    columns: ['status']
});

// Run the search and get the result
var scriptInstanceSearchResult = scriptInstanceSearch.run().getRange({
    start: 0,
    end: 1
});

// Check if all deployments are in use
if (scriptInstanceSearchResult.length > 0 && scriptInstanceSearchResult[0].getValue('status') === 'IN_PROGRESS') {
    // All deployments are in use, call another script
    var scriptTask = task.create({
        taskType: task.TaskType.SCHEDULED_SCRIPT,
        scriptId: "customscript713", // ID of the other script
        deploymentId: null,
        params: {
            custscriptreques_name: invReqName,
            custscriptreques_id: invReqID
        }
    });
    var scriptTaskId = scriptTask.submit();
}
This code first creates a search on the scheduled script instance with the script ID of your script. It then checks the status of the script instances. If all instances are in progress, it creates a task for another script and submits it. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851196349
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847412169
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84588629
Please provide your feedback on this answer.