- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 07:30 AM
Hi all!
I am trying to use confirm() on a onSubmit Client Script and I am running into some problems.
What I am trying to achieve is, Incidents logged to a certain Assignment Group will prompt the analyst if there is no attachment associated with the record.
The GlideAjax for the attachment check works, and the confirmation box pops when save is clicked. However, regardless of what option is selected the form saves.
I have created a client script:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 07:55 AM
Hi @Jackhol ,
I did configure this logic in my PDI it works
Client script :
function onSubmit() {
//Type appropriate comment here, and begin script below
var assGroup = g_form.getValue('assignment_group');
if (assGroup == '477a05d153013010b846ddeeff7b1225') { //i have tried some sample sys_id here
var ga = new GlideAjax('check_open_inc');
ga.addParam('sysparm_name', 'checkAttach');
ga.addParam('sysparm_ticket', g_form.getUniqueValue()); //Sending Ticket sys_id as parameter.
ga.getXMLWait();
var answer = ga.getAnswer();
if (answer) {
var conf = confirm("You have not added an Attachment to this ticket, click Cancel to add an attachment, click Ok to continue");
}
}
}
Script include : I am just returning true from script include to test confirm before form submit
var check_open_inc = Class.create();
check_open_inc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAttach: function(){
var ticket = this.getParameter("sysparm_ticket");
return true; //i am returning true to test confirm
},
type: 'check_open_inc'
});
Result :
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:11 PM
Hi @Jackhol ,
Since its OnSubmit getXMLAnswer() wouldn't work here since its Async form will be submitted before response received from the script include
use getXMLWait() instead (FYI: this wouldn't work if use this in Service portal)
ga.getXMLWait();
answer = ga.getAnswer();
if(
**********
unction onSubmit() {
var assGroup = g_form.getValue('assignment_group');
if (assGroup == 'a60fe98cdb27d85006d43ce3399619d7') {
var ga = new GlideAjax('check_open_inc');
ga.addParam('sysparm_name', 'checkAttach');
ga.addParam('sysparm_ticket', g_form.getUniqueValue()); //Sending Ticket sys_id as parameter.
ga.getXMLWait();
answer = ga.getAnswer();
if (answer == 0) {
var conf = confirm("You have not added an Attachment to this ticket, click Cancel to add an attachment, click Ok to continue");
return conf;
}
}
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:31 AM
Hi Hemanth,
I have tried your script this morning, unfortunately the INC just saves and the Confirmation Box does not appear.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 07:55 AM
Hi @Jackhol ,
I did configure this logic in my PDI it works
Client script :
function onSubmit() {
//Type appropriate comment here, and begin script below
var assGroup = g_form.getValue('assignment_group');
if (assGroup == '477a05d153013010b846ddeeff7b1225') { //i have tried some sample sys_id here
var ga = new GlideAjax('check_open_inc');
ga.addParam('sysparm_name', 'checkAttach');
ga.addParam('sysparm_ticket', g_form.getUniqueValue()); //Sending Ticket sys_id as parameter.
ga.getXMLWait();
var answer = ga.getAnswer();
if (answer) {
var conf = confirm("You have not added an Attachment to this ticket, click Cancel to add an attachment, click Ok to continue");
}
}
}
Script include : I am just returning true from script include to test confirm before form submit
var check_open_inc = Class.create();
check_open_inc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAttach: function(){
var ticket = this.getParameter("sysparm_ticket");
return true; //i am returning true to test confirm
},
type: 'check_open_inc'
});
Result :
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 12:08 AM
Thank you that worked!