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 cannot 'dot walk' in a client script. I'm assuming this is a client script since you are using 'g_form'.
You will need to find the record for the 'opened_by' in the sys_user table and look at the name field.


Wanted to post and say that using ".name" worked well for me.   I am using a Business Rule and tried getDisplayValue() first with no luck.



Thank you!


.name is undefined in Helsinki. Why are reference fields so hard to work with?


Deepak Negi
Mega Sage
Mega Sage

Use below:



g_form.getValue('sys_display.incident.caller_id').toString()



I tried on incident's Called ID field. I get the below Result



find_real_file.png



Mark as helpful/correct if this works for you.



Regards


Deepak


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue === '') {


return;


}


var k1 = g_form.getValue('u_previous_user').toString();


alert(k1);



}


find_real_file.png