How to use GlideAjax in on submit client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 05:37 AM
Hi Team,
I have to do a validation on one variable called tax id ,if the tax id does not exists in account table ,it clear out the value, and is happening with On change client script.But it should not allow to submit the form.But form submission is possible.How can we validate that field on oN Submit.
Thanks,
Karan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 06:05 AM - edited 07-03-2023 06:06 AM
Hi @KARAN24 ,
This has to be achieved by sync ajax using getXMLWait function or if you still want to use the async one follow below options.
Refer following articles:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 06:08 AM
why not clear that variable and make it mandatory when the validation fails.
With this user can submit the form only when correct value is present in that variable tax id
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 07:17 AM
Hi @Ankur Bawiskar ,
I have an On change client script which is clearing the variable value,but the issue is if the user enters the value and directly hits on submit button the form gets submitted.so need a validation for this scenario.
Here is the script include and client script:
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 07:19 AM
if you are showing an error box near that variable then it won't allow submission
OR
you can clear it and make it mandatory
function onChange(control, oldValue, newValue, isLoading) {
if ( newValue == '') {
return;
}
var user_id = g_form.getValue('u_party_tax_id');
var a=user_id.toUpperCase();
//alert(a);
//g_form.addInfoMessage("Timer:" +user_id);
var ga = new GlideAjax('sn_customerservice.getTax');
ga.addParam('sysparm_name', 'getCampus');
ga.addParam('sysparm_u_party_tax_id',a);
ga.getXML(NameDetails);
function NameDetails(response){
//alert("testalert");
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if (answer >= 1) {
// g_form.addInfoMessage("Verified");
g_form.setValue('u_party_tax_id',a);
}
else
{
alert('Please enter Valid Tax ID');
g_form.clearValue('u_party_tax_id');
g_form.setMandatory('u_party_tax_id', true);
}
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader