Can there be an infinite loop when a UE calls a Sc...
# ask-stanley-ai
j
Can there be an infinite loop when a UE calls a Scheduled Script and it updates the same record where UE is deployed?
c
AI generated answer (using internal Slack threads):
Yes, there can be an infinite loop when a User Event (UE) script calls a Scheduled Script and it updates the same record where the UE is deployed. This is because the UE script triggers on record submit, and if the Scheduled Script updates the same record, it will trigger the UE script again, creating a loop. To avoid this, you can use a flag field on the record to indicate whether the update is coming from the Scheduled Script or not. Before the Scheduled Script updates the record, it sets the flag. The UE script then checks this flag before executing, and if it's set, it doesn't run its logic and resets the flag. Here's a simplified example of how this could be implemented: UE Script:
Copy code
javascript
function userEventAfterSubmit(context) {
    var record = context.newRecord;
    var isUpdateFromScheduledScript = record.getValue('custrecord_update_from_ss');
    if (isUpdateFromScheduledScript) {
        record.setValue('custrecord_update_from_ss', false);
        return;
    }
    // Rest of the UE script logic...
}
Scheduled Script:
Copy code
javascript
function execute(context) {
    var recordId = // get the record id to update
    var record = record.load({
        type: 'customrecord_my_record',
        id: recordId
    });
    record.setValue('custrecord_update_from_ss', true);
    // make other updates...
    record.save();
}
In this example,
custrecord_update_from_ss
is a custom checkbox field on the record that is used as a flag to indicate whether the update is coming from the Scheduled Script. ****** 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.846592
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839689434
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838387
Please provide your feedback on this answer.