- 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 07:10 PM
Hi @Jackhol ,
Can u try returning false in ur client script , because of i remember correctly the output of confirm is 'yes' or 'no'. Hence it allows users to save the record.
After confirm on the next line just write
return false;
Instead of return conf
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:41 AM
Hi Danish,
I have tried the below and i have the same outcome:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 07:15 PM - edited 10-20-2023 07:27 PM
Hi @Jackhol,
Try below script.
function 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
if (response === 0) {
var conf = confirm("You have not added an Attachment to this ticket. Click Cancel to add an attachment, click Ok to continue.");
if (!conf) {
// User clicked Cancel, so prevent form submition
g_form.addErrorMessage("Please add an attachment before saving.");
return false;
}
}
}
return true;
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:34 AM
Hi Anand,
Thank you for your script, unfortunately the INC just saves and no confirmation box appears.
Thank you.