
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 10:15 PM
So I have a catalog item that when the requestor clicks on the Submit button a modal pops up with some terms and conditions, then if they don't agree the item doesn't get submitted and if they do agree it is submitted (well at least it should be)
So the issue I have is that when they click the 'I Agree' button on the modal popup, they then have to click the 'Submit' button again on the catalog item to actually log the request.
I had it all working and don't believe I changed anything to make it stop working, but can't get it to work correctly again, so help would be much appreciated 🙂
So this is what I have:
Catalog Client Script on the catalog item
Type - onSubmit
Applies on Catalog Item view - true
Applies on requested items - false
Applies on catalog tasks - false
UI Type - All
Script:
function onSubmit() {
if (typeof spModal != 'undefined') {
if (g_scratchpad.isFormValid) {
return true;
}
spModal.open({
'backdrop': 'static',
'keyboard': false,
message: 'Text goes here',
title: 'Terms and Conditions',
'buttons': [{
label: 'I do not agree',
cancel: true
},
{
label: 'I agree',
primary: true,
}
],
}).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('Error');
gm.renderWithContent('Something has gone wrong');
}
}
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 10:50 PM - edited 11-29-2023 01:55 AM
Hi @Moedeb
It should be because of this line below from your script, the getActionName API returns nothing.
var actionName = g_form.getActionName();
The correct place should be before the Modal get open, right after the user click Submit button.
Let's try my adjustment below.
function onSubmit() {
if (typeof spModal != 'undefined') {
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName(); //move to here
spModal.open({
'backdrop': 'static',
'keyboard': false,
message: 'Text goes here',
title: 'Terms and Conditions',
'buttons': [{
label: 'I do not agree',
cancel: true
},
{
label: 'I agree',
primary: true,
}
],
}).then(function(confirmed) {
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
return true;
});
g_scratchpad.isFormValid = false;
return false;
} else {
var gm = new GlideModal();
gm.setTitle('Error');
gm.renderWithContent('Something has gone wrong');
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 10:41 PM
Hi @Moedeb
The code you have written is looks good..& also I have checked in my PDI
If user clicks on 'I agree' , request is getting submitted ....without having to click on submit button again...
Not sure but its working fine....
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 10:45 PM
@Vishal Birajdar thanks - I created it in my Dev instance and the issue occurred, then as I said thought I didn't change anything, so maybe just an issue in that instance, so moved it to my test instance and same problem again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 11:35 PM
Hi @Moedeb
What's the 'Request Method' for catalog item...(submit,request or order) ...?
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 02:46 PM
@Vishal Birajdar we normally use Submit, I've tried both submit and request and have the same issue with both.
I just tried it in my personal instance and it also worked properly, but just doesn't in my Dev or Test environments.
The only thing I can think off that is different is that we don't use the confirmation window, it is meant to just submit right away. I can't see anything in the script that should cause an issue because of that though?