- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 01:28 AM
Hello Community !
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:34 AM
Did you try this solution?
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 06:50 AM
this worked for me in onLoad catalog client script
I hope I answered your question and you can enhance it further.
function onLoad() {
var element = this.document.getElementsByClassName('btn btn-primary btn-block text-overflow-ellipsis ng-binding ng-scope');
element[0].style.display = 'none';
}
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 02:49 AM
You're using GlideAjax.getXMLAnswer(), which is asynchronous. This means the onSubmit() function completes before setData() finishes — so the form submission proceeds before the validation result is received.
If your goal is to validate the combination of account, contact_name, and catalog item whenever a specific field changes (e.g. contact_name or account), you can do this via onChange.
Here’s how to convert your script to an onChange client script (example: triggered when contact_name)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
if (g_user.hasRole('sn_customerservice_agent')) {
var ga = new GlideAjax('catalogUtils');
ga.addParam('sysparm_name', 'hasExistingRITM');
ga.addParam('sysparm_account', g_form.getValue('account'));
ga.addParam('sysparm_userId', newValue); // since contact_name is triggering
ga.addParam('sysparm_catalogItem', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
if (response === 'false') {
g_form.showFieldMsg('contact_name', getMessage('You are not allowed to order as there is an existing request for this customer'), 'error');
}
});
}
}
Please mark correct/helpful if this helps you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:59 AM
Try this, button will not disable but request can not be submitted for false
function onSubmit() {
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
if (g_user.hasRole('sn_customerservice_agent')) {
var ga = new GlideAjax('catalogUtils');
ga.addParam('sysparm_name', 'hasExistingRITM');
ga.addParam('sysparm_account', g_form.getValue('account'));
ga.addParam('sysparm_userId', g_form.getValue('contact_name'));
ga.addParam('sysparm_catalogItem', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
var answer = response;
alert('response: ' + answer);
if (answer == 'false') {
alert(getMessage('You are not allowed to order as there is an existing request for this customer'));
g_scratchpad.isFormValid = false;
} else {
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
});
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 06:40 AM
Hi @is_12
You cannot use asynchronous GlideAjax inside onSubmit() if you want to prevent submission.
Use getXMLWait() (Synchronous Call)
Since you said getXMLWait() is working, that’s the expected behavior, as it waits for the server response.
Note: ServiceNow discourages getXMLWait() in client scripts because it's synchronous and can cause the UI to freeze temporarily.
You can try this script:
function onSubmit() {
if (g_user.hasRole('sn_customerservice_agent')) {
var ga = new GlideAjax('catalogUtils');
ga.addParam('sysparm_name', 'hasExistingRITM');
ga.addParam('sysparm_account', g_form.getValue('account'));
ga.addParam('sysparm_userId', g_form.getValue('contact_name'));
ga.addParam('sysparm_catalogItem', g_form.getUniqueValue());
var answer = ga.getXMLWait();
var response = answer.responseXML.documentElement.getAttribute("answer");
if (response == 'false') {
alert(getMessage('You are not allowed to order as there is an existing request for this customer'));
return false;
}
}
return true;
}
Thanks and Regards,
Chiranjeevi R
Please mark as Correct Answer/Helpful, if applicable.
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 06:54 AM
@palanikumar @Ankur Bawiskar @ ChiranjeeviR @Muhammad Salar @sunil maddheshi
Tons for Thanks for all your replay, It is working now