await dialog prompt in save record client script
# ask-stanley-ai
p
await dialog prompt in save record client script
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** The
N/dialog
module in SuiteScript is asynchronous, which means it doesn't halt the execution of the script while waiting for user input. This is different from the vanilla JavaScript
confirm
function, which is synchronous and does halt the script execution. In the context of a
saveRecord
client script, this means that by the time the user interacts with the dialog box, the
saveRecord
function has already finished executing and returned a value. This is why you're seeing the function return
false
regardless of the user's input. If you want to use
N/dialog
in a
saveRecord
function, you'll need to return
false
from the
saveRecord
function to prevent the record from being saved, and then programmatically click the save button again in the callback of your promise. Here's a rough example of how you might do this:
Copy code
javascript
function saveRecord(context) {
    var currentRecord = context.currentRecord;
    var isDuplicate = checkForDuplicates(currentRecord); // replace with your duplicate checking logic

    if (isDuplicate) {
        N.dialog.confirm({
            title: 'Duplicate Record',
            message: 'This record appears to be a duplicate. Are you sure you want to save it?'
        }).then(function(result) {
            if (result) {
                // User clicked "OK", so save the record
                document.getElementById('main_form').submit();
            }
        });

        // Prevent the record from being saved until the user has responded to the dialog
        return false;
    }

    // No duplicates found, so allow the record to be saved
    return true;
}
However, this approach is more complex and potentially more error-prone than simply using the synchronous
confirm
function. If you don't specifically need to use
N/dialog
, it may be simpler and more reliable to use
confirm
instead.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.857355595
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840273321
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836429298
Please provide your feedback on this answer.