g_form.getReference(variable, callback function) showing undefined value.

prabhmeet
Giga Expert

Hi,

I have created a new table new_line_of_business which contains a reference column lob_name to another table (cmdb_line_of_business) which has names field.

Now, in a catalog item, I have a variable 'lob' where I am referencing the new_line_of_business_table.

There is a variable 'access' in the catalog item where I have to display a prefix and Line of business name selected by the user- 

Here is the onchange  code - 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var a = g_form.getReference('lob', callBackFunc);
}
function callBackFunc(a)
{

var roleName = a.name + '-';
g_form.setValue('access', 'CP/HCV-'+roleName);
}

find_real_file.png

Now it is displaying undefined but it should show ecom. Can anyone help why this is happening?

In the referenced table , new_line_of_business, the lob_name col is referencing another table (I Tried making lob_name string also, it didn't work )

Please help.

6 REPLIES 6

Try using the function getDisplayValue() to get the string values instead of sys id 

Koushik Ningara
Tera Contributor

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading'') {
return;
}

var a = g_form.getReference('lob', callBackFunc);          // consider trying ('lob_name', callBackFunc);
}
function callBackFunc(a)
{

var roleName = "CP/HCV-" +a.name+ "-";
g_form.setValue("access", roleName);
}

 

Even if it is not working out, try using this code line--> var a = g_form.getReference('lob', callBackFunc);

in a call back function only. not inside the body of this function function

onChange(control, oldValue, newValue, isLoading) {}

 

Thanks,

Koushik

ServiceNow Admin