How to get the value from sys_id in the client script?

Murthy JN1
Tera Contributor

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?

1 ACCEPTED SOLUTION

Raghu Ram Y
Kilo Sage

@Murthy JN 

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

View solution in original post

6 REPLIES 6

Sourabh26
Giga Guru

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

Nikita30
Mega Sage

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!

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.

 

Raghu Ram Y
Kilo Sage

@Murthy JN 

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