getReference() call back function

vai
Kilo Contributor

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;
}

 

1 ACCEPTED SOLUTION

Gosia Urbanska
Giga Guru

From wiki

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideFormGetReference_String_Funct...

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

 

 

View solution in original post

6 REPLIES 6

Yes, I do not see any better solution;

Thank you for explaining this in laymen.