OnSubmit Catalog client script not working
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 07:35 AM
function onSubmit() {
var user = g_form.getValue('requestbytmp2_name');
var ga = new GlideAjax('CheckOAuthToken');
ga.addParam('sysparm_name', 'isTokenValid');
ga.addParam('sysparm_user_id', user);
ga.getXML(GetData);
function GetData(response) {
var ans = response.responseXML.documentElement.getAttribute("answer");
if (ans == 'true') {
alert('You have a valid token.');
g_form.submit();
return true;
} else if (ans == 'false') {
alert('You do not have a valid token. Please login to a new session before proceeding.');
return false;
} else {
alert('Unexpected response: ' + ans);
return false;
}
}
}
I am using this script to prevent form submission when isTokenValid returns false, but it is allowing the form submission. I tried with XML wait but it is not working. Is there a better way to achieve it?
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 08:17 AM
Hi @Laxmi Sadhana K ,
Refer this article
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579
Please mark my response as helpful and accept it as solution if helped
Regards
Chaitanya
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 09:04 AM
Hi @Laxmi Sadhana K ,
function onSubmit() {
if (g_scratchpad.isFormValid) {
return true;
}
var user = g_form.getValue('requestbytmp2_name');
var ga = new GlideAjax('CheckOAuthToken');
ga.addParam('sysparm_name', 'isTokenValid');
ga.addParam('sysparm_user_id', user);
ga.getXMLAnswer(function(ans) {
if (ans == 'true' || ans == true) {
alert('You have a valid token.');
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
} else if (ans == 'false') {
alert('You do not have a valid token. Please login to a new session before proceeding.');
return false;
} else {
alert('Unexpected response: ' + ans);
return false;
}
});
return false;
}
try this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya