I'm creating an expense report for a cash sale in ...
# ask-stanley-ai
l
I'm creating an expense report for a cash sale in the beforeLoad stage, but i'm not seeing it, the expense is created but sublist is not updated, I have to refresh again to see the previously create, also the before load is running twice, In what stage could this sublist being loaded before the beforeload?
c
AI generated answer (using internal Slack threads):
The sublist could be loaded in the
beforeSubmit
stage. The
beforeLoad
stage is used to prepare the form for display in the UI, and it runs every time the form is displayed. This includes when the form is initially loaded, when it's refreshed, and when it's submitted. If you're seeing the
beforeLoad
stage run twice, it could be because the form is being loaded, then refreshed. If the sublist isn't being updated until after the
beforeLoad
stage has run, then the sublist changes won't be visible until the next time the form is refreshed. To avoid this, you could try moving the sublist update to the
beforeSubmit
stage. This stage runs after the user has made their changes and clicked the submit button, but before the record is actually saved. This would allow you to update the sublist before the record is saved, so the changes should be visible immediately after the save, without needing to refresh the form. Here's a sample code snippet for a
beforeSubmit
function:
Copy code
javascript
function beforeSubmit(scriptContext) {
    var record = scriptContext.newRecord;
    var sublistCount = record.getLineCount({sublistId: 'your_sublist_id'});
    for (var i = 0; i < sublistCount; i++) {
        var sublistValue = record.getSublistValue({
            sublistId: 'your_sublist_id',
            fieldId: 'your_field_id',
            line: i
        });
        // Do something with sublistValue...
    }
}
Remember to replace
'your_sublist_id'
and
'your_field_id'
with the actual ID of your sublist and the field you want to update. ****** 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.826300502
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.820816
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819644332
Please provide your feedback on this answer.