
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2019 05:48 AM
In the service portal we would like to start using Modals instead of alerts. One issue I'm having is when I write a script like this:
function onSubmit() {
if (typeof spModal != 'undefined') {
spModal.open({
message: 'Hello',
title: ''
});
} else {
var gm = new GlideModal();
gm.setTitle('');
gm.renderWithContent('Hello');
}
}
In the service portal after pushing submit, the form will submit after a few seconds without the user having pushed ok or closing the modal.
Is there any way to get it to perform more like an alert, requiring the modal to be closed before it submits and moves on to the next page?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2019 11:46 AM
I have finally solved this problem by using g_scratchpad
if (typeof spModal != 'undefined') {
if (g_scratchpad.isFormValid) {
return true;
}
spModal.open({
message: 'HELLO',
title: ''
}).then(function(confirmed){
g_scratchpad.isFormValid = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;});
g_scratchpad.isFormValid = false;
return false;
} else {
var gm = new GlideModal();
gm.setTitle('');
gm.renderWithContent('HELLO');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2024 02:49 PM
Hi @Mark Endsley does this solution works for Catalog item record producer?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2024 04:54 AM
This should work for both Catalog Items and Record Producers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2024 07:27 PM
Thank you for your kind reply. It works, as you said; however, I have some questions.
1- I am getting this 'confirmed' is declared but its value is never read. error message. Is that right?
}).then(function(confirmed) {
g_scratchpad.hasAcknowledge = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;
2- would it cause an issue to change
function onSubmit() {
//Type appropriate comment here, and begin script below
if (typeof spModal != 'undefined') {
if (g_scratchpad.hasAcknowledge) {
return true;
}
spModal.open({
title: 'ACKNOWLEDGEMENT',
message: 'By submitting this request,',
buttons: [{
label: 'Cancel',
cancel: true
},
{
label: 'Confirm',
primary: true
}
]
}).then(function(confirmed) {
g_scratchpad.hasAcknowledge = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;
});
g_scratchpad.hasAcknowledge = false;
return false;
} else {
var gm = new GlideModal();
gm.setTitle('');
gm.renderWithContent();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 04:34 AM - edited ‎07-23-2024 04:35 AM
That is just a warning message because in your function you never use confirmed to do anything. Normally you would want to do if(confirmed) around this block in the .then
But the message you are getting shouldn't stop your code from running, it will just mean it doesn't actually care whether or not the user confirmed or not, it will always carry out the functionality in that block.
g_scratchpad.hasAcknowledge = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2024 11:12 AM
Hello @Mark Endsley
Please accept in advance if I am bothering you. I am new to scripting and Sp.
I used your code and changed it to something I understood better. Unfortunately, I am getting an error message
function onSubmit() {
//Type appropriate comment here, and begin script below
if (typeof spModal !== "undefined" && !g_form._hasConfirmed) {
spModal.open({
title: "Acknowledgment:",
message: "",
buttons: [{
label: "Cancel",
cancel: true
},
{
label: "Confirm",
primary: true
}
]
}).then(function(confirm) {
if (confirm) {
g_form._hasConfirmed = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;
}
});
return false;
}
}