Hi, i have an button on a suitelet, by clicking th...
# ask-stanley-ai
x
Hi, i have an button on a suitelet, by clicking the button, it will start to run a map reduce script. What can i do to avoid people clicking the button when the map reduce script is in process?
c
AI generated answer (using internal Slack threads):
To avoid people clicking the button when the map reduce script is in process, you can implement a locking mechanism. This can be done by using a Suitelet that kicks off the map reduce task and also tracks its status. When the button is clicked, the Suitelet can check if the map reduce script is already running. If it is, the Suitelet can return a message to the user indicating that the process is already in progress and prevent the script from being triggered again. If the script is not running, the Suitelet can start the map reduce script and update the status to 'running'. Here is a simplified example of how you might implement this:
Copy code
javascript
var scriptTask = task.create({taskType: task.TaskType.MAP_REDUCE});
scriptTask.scriptId = 'customscript_my_map_reduce';
scriptTask.deploymentId = 'customdeploy_my_map_reduce';

// Check if the script is already running
var scriptStatus = scriptTask.checkStatus();
if (scriptStatus.status === task.TaskStatus.RUNNING) {
    // If the script is running, inform the user and prevent the script from being triggered again
    context.response.write('The process is already in progress. Please wait until it completes before clicking the button again.');
} else {
    // If the script is not running, start it and update the status to 'running'
    var scriptTaskId = scriptTask.submit();
    context.response.write('The process has been started. Please wait until it completes before clicking the button again.');
}
Remember to replace 'customscript_my_map_reduce' and 'customdeploy_my_map_reduce' with your actual script ID and deployment ID. ****** 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.858196259
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.852167249
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851874352
Please provide your feedback on this answer.
Thank you for your feedback