- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 03:45 AM
Hi Everyone,
i've created an OnChange client script on a variable set, the script should return false if the age (through DOB is more than 21 )and should not allow the submission of the record producer, but return false; is not working.
the script throws alert if age is more than 21 , but it still submits the form, i want to prevent form submission.
it throws the error but takes in the value under the variable set.
any support would be much appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 07:53 AM - edited ‎02-12-2024 07:54 AM
Hi @kartikey,
I've tested below script as onSubmit script on the variable set as working in my instance:
So this will work for every row submitted in your MRVS separately. It will not work in this form on the catalog item.
function onSubmit() {
if (g_scratchpad.isFormValid)
return true;
var dob = g_form.getValue('date_of_birth');
alert(dob);
var ga = new GlideAjax('CallerDeatils');
ga.addParam('sysparm_name', 'getAge');
ga.addParam('sysparm_dob', dob);
ga.getXML(callBackFunction);
return false;
}
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer > 21) {
g_form.addErrorMessage('test');
return false;
}
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 03:48 AM - edited ‎02-12-2024 04:02 AM
Hi @kartikey
You will have to abort the form submission, while te async function runs, and trigger form submission again after it has validated correctly.
var dob = g_form.getValue('date_of_birth');
if (g_scratchpad.isFormValid)
return true;
var ga=new GlideAjax('CallerDeatils');
ga.addParam('sysparm_name','getAge');
ga.addParam('sysparm_dob',dob);
ga.getXML(callBackFunction);
//then return false to halt submission (for now)
return false;
function callBackFunction(response){
var answer=response.responseXML.documentElement.getAttribute('answer');
// alert(answer);
if(answer>21){
alert(" example alert");
//g_form.clearValue('date_of_birth');
return false;
}
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 04:44 AM - edited ‎02-12-2024 04:45 AM
Hi Peter,
This is still not working, tried after making the above modification. the form is still submitting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 05:05 AM
Hi @Peter Bodelier ,
it does work with onSumit to stop the submission of the form BUT only if greater than 21 age it submitted first via the variable set
but if i input less than 21 i.e. test 2 record submitted first, it does not work
iterating only once on OnSubmit script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 05:08 AM
Hi @kartikey
I'll try to rebuild your exact use case, and will get back to you.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.