We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Show user name on the updated by field

manoj12398
Giga Contributor

Hi,

I have created a custom field u_updated_by_name and I want to populate updated by (sys_updated_by) field value in it. but that shows user ID. How can I populate current value of sys_updated_by in my custom field but should show name of the user instead of user id

Kindly suggest. Thanks

7 REPLIES 7

rlatorre
Kilo Sage

Updated by is not a reference field so you will need to lookup the user record.



Try:


var gr = new GlideRecord('sys_user');


if (gr.get('user_name', current.sys_updated_by)){


  current.u_updated_by_name = gr.name;


}




Or you can change your custom field to a reference field to the user table. This will give you access to the user record easily.


var gr = new GlideRecord('sys_user');


if (gr.get('user_name', current.sys_updated_by)){


  current.u_updated_by_name = gr.sys_id;


}


Thank you so much this actually helped me

Abhinay Erra
Giga Sage

Use calculated field and put this in the calculation script



(function calculatedFieldValue(current) {


  var gr= new GlideRecord('sys_user');


  if(gr.get('user_name',current.getValue('sys_updated_by')))


  return gr.name;   // return the calculated value


  return'';


})(current);


Thanks Abhinay. It works perfectly.