I want to run a scheduled script every 15 minutes,...
# ask-stanley-ai
j
I want to run a scheduled script every 15 minutes, but only during certain days and within a certain time window during the day. Is there an alternative to achieving this goal without creating a whole bunch of different script deployments?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** Yes, it is possible to run a scheduled script every 15 minutes, but only during certain days and within a certain time window during the day. However, NetSuite's scheduling system does not provide a direct way to achieve this. One workaround is to use multiple deployments of the same script, each with a different start time. This way, you can set each deployment to run at a different 15-minute interval. However, this method can be cumbersome if you need to cover a large time window or multiple days. Another approach is to use a combination of scheduled scripts and SuiteScript's
N/task
module. You can create a master scheduled script that runs every 15 minutes and checks the current time and day. If the current time and day fall within your desired window, the master script can use the
N/task
module to trigger another script. Here's a rough example of how the master script might look:
Copy code
javascript
define(['N/task', 'N/runtime'], function(task, runtime) {
    function execute(context) {
        var currentTime = new Date();
        // Replace these with your desired time window and days
        var startTime = new Date();
        startTime.setHours(9, 0, 0); // 9:00 AM
        var endTime = new Date();
        endTime.setHours(17, 0, 0); // 5:00 PM
        var validDays = [1, 2, 3, 4, 5]; // Monday to Friday

        if (currentTime >= startTime && currentTime <= endTime && validDays.includes(currentTime.getDay())) {
            var scriptTask = task.create({taskType: task.TaskType.SCHEDULED_SCRIPT});
            scriptTask.scriptId = 'customscript_your_script_id'; // Replace with your script's ID
            scriptTask.deploymentId = 'customdeploy_your_deployment_id'; // Replace with your deployment's ID
            scriptTask.submit();
        }
    }

    return {
        execute: execute
    };
});
Please note that this is a simplified example and you may need to adjust it to fit your specific needs. Also, keep in mind that scheduled scripts are subject to governance limits and other restrictions, so make sure your scripts are optimized to run efficiently.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.877502561
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.861267209
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.860595882
Please provide your feedback on this answer.