- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 09:42 AM
I have a scenario where i need to get the values from a reference field popup in clientscript during onsubmit of form.
below is my code
the issue is before the ValidateCus function completed its execution, the if condition of if(validationFailed == true) is executed and as the initial value of variable 'validationFailed' is false the form is submitted.
var x = g_form.getReference('inv_customer', validateCus);
var validationFailed = false;
function validateCus(customerInfo)
{
if(g_form.getValue('fm_cst') == customerInfo.cst)
{
validationFailed = true;
}
}
if(validationFailed == true)
{
return false;
}
else
{
return true;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 10:15 AM
From wiki
getReference(String fieldName, Function callBack)
Returns the GlideRecord for a specified field.
If a callback function is present, this routine runs asynchronously, and browser (and script) processing will continue normally until the server returns the reference value, at which time the callback function will be invoked. If a callback function is not present, this routine runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response.
In your case since this is asynchronous call onSubmit script will not work; Try to move your validation to onChange

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 10:11 AM
Change it to On change or try below link if you want it as asynchronous
https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 10:15 AM
From wiki
getReference(String fieldName, Function callBack)
Returns the GlideRecord for a specified field.
If a callback function is present, this routine runs asynchronously, and browser (and script) processing will continue normally until the server returns the reference value, at which time the callback function will be invoked. If a callback function is not present, this routine runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response.
In your case since this is asynchronous call onSubmit script will not work; Try to move your validation to onChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 10:21 AM
my concern is i have 6 text fields on which the validation needs to be performed, do I need to have 6 on change client scripts ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 10:34 AM
Unfortunately onSubmit and Ajax/getReference with a callback do not really work together because the answer usually would come back after the script is completed.