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.

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

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can use a script action on login to add some data to the current session data. If you're looking to get at the data from a client script, that's a pretty good bet.



Session Client Data - ServiceNow Wiki


Brad,



Is there no better way for me to set the default value of this field to the value of the current users u_data field on sys_user?



It seems like I should be able to access the u_data field if I can get the current user (gs.getUser()).


You need to create a client callable script include in which you could glide record user table and return u_data then call the script include in default value as follow


javascript:script_include


Gupreet,



Using a script include makes sense. Do you have any advise on how to determine the current user within the script include, or is there a way to pass gs.getUser() to the script include?



Thanks!