Use gs.getUser() to get custom user property?

josh_tessaro
Giga Expert

We have a custom user attribute, it is a field called u_data containing a string.

I want to set a catalog variable field to default to the value of <current user>.u_data, however it appears that gs.getUser() can only access properties that have functions defined to return them (Getting a User Object - ServiceNow Wiki). Is there a way to define a function that returns this custom property to client scripts?

Thanks!

1 ACCEPTED SOLUTION

ahaz86
Mega Guru

have you tried


gs.getUser().getRecord().getValue('u_data');


View solution in original post

9 REPLIES 9

You can just use gs.getUser() inside of your script include. You could also grab the gliderecord for the user in the default value like:



javascript: var user = new GlideRecord('sys_user'); user.get(gs.getUserID()); user.u_data;


1. Create a client callable script include getData having following type of code


function getData(){


        var gr =   new GlideRecord('sys_user');


gr.get(gs.getUserID());


return gr.u_data ;


}



default value:      


javascript:getData()


ahaz86
Mega Guru

have you tried


gs.getUser().getRecord().getValue('u_data');


Clean and easy answer. It returns a GlideMemoryRecord which is cached at login so just be aware of that possible limitation if data being retrieved could change during a user's session.


Have the below code in Default Value of the Variable. This will auto populate with the current user logged in. The Reference should point to the User Table (sys_user)



javascript:gs.getUserID()