Issue with Saving Record Using g_modal.confirm in onSubmit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello everyone,
I am trying to show a modal using g_modal.confirm in an OnSubmit Client Script when the Save button is clicked. I want the record to be saved only if the user clicks the OK button in the modal.
However, when I press OK, nothing happens and the record is not saved.
Below is the script I am using. I referred to other scripts, but honestly, I do not fully understand the function(confirm) part and so on.
function onSubmit() {
var dlgMessage = "XXXXXXXXXX";
g_modal.confirm(getMessage("YYYYYYYYYYY"), dlgMessage, function(confirm) {
if (confirm) {
g_form.save();
}
});
return false;
}
If there are any mistakes or improvements in my implementation, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Write a onSubmit client script
UI type - should be Mobile/Service Portal for workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
function onSubmit() {
var dlgMessage = "XXXXXXXXXX";
g_modal.confirm(getMessage("YYYYYYYYYYY"), dlgMessage, function(confirm) {
if (confirm) {
return true;
}
});
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ao7 ,
var confirmed = false;
function onSubmit() {
if (confirmed) {
// If already confirmed, allow the save
return true;
}
// Show the confirmation dialog
g_modal.confirm(
getMessage("YYYYYYYYYYY"), // Title
"XXXXXXXXXX", // Message
function(result) {
if (result) {
confirmed = true;
g_form.save(); // This triggers onSubmit again, but now confirmed is true
}
}
);
// Prevent the form from saving until the user confirms
return false;
}
if you found above helpful please mark it helpful
Thanks,
Abin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Dear All,
Thank you for your advice!
The issue has been resolved using the script below, so I’d like to share it.
function onSubmit() {
if (g_form.isNewRecord() || typeof g_scratchpad === 'undefined')
return true;
if (g_scratchpad.already_submitted)
return true;
var dlgMessage = "XXXXXXXXXX";
g_modal.confirm(getMessage("YYYYYYYYYYY"), dlgMessage, function(confirm) {
if (confirm) {
g_scratchpad.already_submitted = true;
g_form.save();
}
});
return false;
}