g_form.getReference(variable, callback function) showing undefined value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 12:31 PM
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);
}
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 12:12 AM
Try using the function getDisplayValue() to get the string values instead of sys id

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 11:44 PM
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