Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Getting value of the field instead of sys_id

ravali6
Giga Contributor

I have a script where I do a GlideRecord query to the request table. Once I get the records, I am getting to the value of the opned by field. But since opened by is a reference field, it is returning sys_id. How can I get the displayed value ?

Below is the script :

var gr = new GlideRecord("sc_req_item");
gr.addQuery("u_requested_for", g_form.getValue("emp_name"));
gr.addQuery("stage",'!', "waiting_for_approval");
gr.query();

if(gr.next())
{
alert("A request has already been submitted by " + gr.opened_by); // this is returming sys_id, I need the value

}


Please let me know if anyone has any suggestions.

22 REPLIES 22

You can't do this with a client script the way you are attempting it. There is a response by Terri that goes over a way to get this to work as a client script.

I think we were assuming this was a server side script you were running or we'd have known .name or .getDisplayValue wouldn't work in this case.


ravali6
Giga Contributor

Hi Aaaron,

Thanks for the reply, yes I tried with the getDisplayValue(), seems to be not working.


Michael Kaufman
Giga Guru

You can try this:



var gr = new GlideRecord("sc_req_item");
gr.addQuery("u_requested_for", g_form.getValue("emp_name"));
gr.addQuery("stage",'!', "waiting_for_approval");
gr.query();
if(gr.next())
{
alert("A request has already been submitted by " + gr.opened_by.name); // this is returning sys_id, I need the value
}


this is working for me.

randrews
Tera Guru

try gr.opened_by.name