- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:34 AM
I wanted to prevent form submission where requested on catalog item who is having the division and subdivision is customer and support in sys_user table then that user will be able to submit the catalog item form or else not.
i tried to get this solve with the help of getReference method in onsubmit client script but it is not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:19 AM
Hi,
so what script did you use?
you can use onChange client script + GlideAjax
OR
you can use onSubmit with GlideAjax and custom solution for synchronous ajax call
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 05:44 AM
Hi,
you can use onChange client script + GlideAjax
OR
you can use onSubmit with GlideAjax and custom solution for synchronous ajax call
But remember these points:
1) Asynchronous GlideAjax won't work as by the time ajax function returns the value your form will get submitted
2) Synchronous GlideAjax is not allowed in portal and scoped application
Refer this link
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:29 AM
HI,
please try below code:-
Script Include: It should be client callable
var CheckRecords = Class.create();
CheckRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['email'] = gr.getValue('email');
obj['manager'] = gr.getValue('manager');
obj['location'] = gr.getValue('location');
obj['region'] = gr.region.toString();
}
return JSON.stringify(obj);
},
type: 'CheckRecords'
});
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for_variable')); // give here your variable name
ga.getXMLAnswer(function(answer){
if(answer != 'not found'){
var parser = JSON.parse(answer);
g_form.setValue('manager_variable', parser.manager); // give here manager variable name
g_form.setValue('email_variable', parser.email); // give here email variable name
g_form.setValue('location_variable', parser.location); // give here location variable name
g_form.setValue('region_variable', parser.region); // give here region variable name
}
});
//Type appropriate comment here, and begin script below
}
Hope this helps.
please mark my answer as ✅ Correct & Helpful based on the validations.