- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 10:56 AM
Can anyone help me why getReference not working as expected for Onchange Client script. Below a sample example.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci= g_form.getReference('cmdb_ci', doAlert);
}
function doAlert(ci) {
alert("CI is:"+ci.getDisplayValue());
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 11:10 AM
Hi dola
You can use g_form.getDisplayBox('cmdb_ci').value; to get the displayvalue.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci= g_form.getDisplayBox('cmdb_ci').value;
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 11:05 AM
var ci= g_form.getReference('cmdb_ci', doAlert);
} //This doesnt seem like it has an opening bracket? - is this necessary at all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 11:10 AM
Hi dola
You can use g_form.getDisplayBox('cmdb_ci').value; to get the displayvalue.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci= g_form.getDisplayBox('cmdb_ci').value;
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 11:25 AM
Thanks for your response. But can you tell what's issue with getReference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 10:10 PM
getDisplayValue() will not work in client script.
and if you want to use getReference to get the display value then try below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci= g_form.getReference('cmdb_ci', doAlert);
}
function doAlert(ci) {
alert("CI is:"+ci.name));
}
https://servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP