Anyone seen this issue before with SuiteScript (Ma...
# ask-stanley-ai
m
Anyone seen this issue before with SuiteScript (Map/Reduce) where it works as expected when run manually the first time but starts throwing errors when triggered a second time (UNEXPECTED_ERROR ). To make it work I have to re-upload the same script code to the file cabinet (i.e. no changes) before triggering the script.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that the issue you're experiencing with SuiteScript (Map/Reduce) could be due to a few reasons: 1. Circular Dependencies: If your script has circular dependencies, it might cause issues. One user mentioned that they had a problem when their script imported two module libraries, and one of these libraries also depended on the other. The issue was resolved when they removed the
.js
extension from the filename in the import statement. 2. Concurrency Issues: If you're trying to trigger the same Map/Reduce script more than once from a User Event while another one has not finished executing, you might encounter an error. This is because N/task is not thread-safe. If two scripts submit a task at the same time, they may choose the same deployment and one of them will throw the "already running" error. Some potential solutions to this issue include: - Using a try-catch loop that just tries it again. - Creating a new deployment of your Map/Reduce in your User Event and specifying that deployment while creating the task. - Implementing a lock via a custom record to ensure that only one script can submit a task at a time. 3. Time Limit Error: If you're trying to save files to the file cabinet and you're getting an error, it might be due to a time limit error. Even if your script is not particularly slow, you might still encounter this issue. Remember to always test your scripts thoroughly and ensure that they are optimized for performance to avoid such issues. ****** 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.841712058
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84010464
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830407917
Please provide your feedback on this answer.