Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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
Tera 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

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