Can a record.submitFields in a beforeLoad user eve...
# ask-stanley-ai
c
Can a record.submitFields in a beforeLoad user event script cause an infinite loop?
c
AI generated answer (using internal Slack threads):
Yes, a
record.submitFields
in a beforeLoad user event script can cause an infinite loop. This can happen if the
record.submitFields
triggers the same user event script again, and there is no condition to break this cycle. In the provided conversations, a user was trying to use
record.submitFields
to update a custom record in a beforeLoad user event script. However, the changes were not persisting to page load, causing the user to manually reload the page. When they tried to use
redirect.toRecord
to reload the page, they ended up in an infinite redirect loop. To avoid this, you can add a parameter to
redirect.toRecord
and read it in your script. If that parameter is set, you can skip the
redirect.toRecord
. Here is a code sample provided in the conversations:
Copy code
javascript
const redirectParams = {
    isReloaded: 'T'
};

const params = scriptContext.request.parameters;

if (params.isReloaded !== 'T') {
    redirect.toRecord({
        type: newRec.type,
        id: newRec.id,
        parameters: redirectParams
    });
}
In this code,
isReloaded
is a parameter that is checked before the
redirect.toRecord
is called. If
isReloaded
is not set to 'T', the script will redirect to the record, otherwise, it will skip the redirect, preventing an infinite loop. ****** 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.846691072
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843246818
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842013955
Please provide your feedback on this answer.