Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client script abort submission

Jake Sadler
Kilo Sage

I have the below client script that runs on the change table.I'm trying to stop the form from being submitted/saved when the user selects cancel but when I select cancel it still saves.

 

function onSubmit() {

var state = g_form.getValue('state');
var req = g_form.getValue('requested_by');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', req);
gr.query(myCallbackFunction);
gr.next();

function myCallbackFunction(gr) {
gr.next();
if (state == -94 || state == 50 && gr.company != g_form.getValue('company')) {
//state == -94 || state == 50 &&

var x = confirm('Requester does not belong to the identified Company. Are you sure you want to save?');

if (x == false) {

return false;

}

}


}

}

 

Any help would be much appreciated

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I believe this covers the issue you are facing:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579

View solution in original post

1 REPLY 1

Community Alums
Not applicable

I believe this covers the issue you are facing:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579