- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 12:17 AM
Hi,
I have an onLoad client script that displays the parent incident if we open a child. I am getting sys_id instead of the actual value. Please guide.
This is the script:
function onLoad() {
if(g_form.parent_incident != '')
{ alert("This is hte parent of " +g_form.getValue('parent_incident')); }}
Someone has taught me using GlideRecord is not a suggested practice in Clinet Scripts. How to populate actual value instead of sys_id?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 12:42 AM
Yes, it is not a best practice to use glide record on client script, so you can get the value by using client script it self..
Try the below On Load Client script.
function onLoad() {
var usr = g_form.getReference('giveparentfieldname',callBack);
}
function callBack(usr){
alert(usr.number);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 12:38 AM
Hi,
You need to call a server side script (script include) to get the related value from the table.
Go through below examples to configure for the same.
https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_learnv2_scripting_quebec_extending_glideajax
https://docs.servicenow.com/bundle/paris-application-development/page/script/ajax/topic/p_AJAX.html
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 12:39 AM
Hi Murthy JN,
Please try below code.
function onLoad() {
if(g_form.getValue("parent_incident") != '')
var parentinc = g_form.getReference("parent_incident",getDetails());
}
function getDetails(parentinc)
{
alert(parentinc.number);
}
Please mark the response as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 03:39 AM
Nikita,
Thanks for your answer. It helped, but I think callback function should not have () while calling it.
var parentinc = g_form.getReference("parent_incident",getDetails); should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-31-2022 12:42 AM
Yes, it is not a best practice to use glide record on client script, so you can get the value by using client script it self..
Try the below On Load Client script.
function onLoad() {
var usr = g_form.getReference('giveparentfieldname',callBack);
}
function callBack(usr){
alert(usr.number);
}
}