I'm trying to set a default value on a reference field called "u_director_name". When a user creates a Change Request I want the Director value [u_director] from their User record to pass to "u_director_name".

Lisa_Wiegmann
Giga Guru

I'm trying to set a default value on a reference field called "u_director_name".  When a user creates a Change Request I want the Director value [u_director] from their User record to pass to "u_director_name".  

1 ACCEPTED SOLUTION

Looks like maybe you've got some security settings getting in the way.  You'll probably need to create a script include with the 'gs.getUser().getRecord().getValue('u_director_name');' line I gave you before.  Then you can call your script include in your default value instead.  It's really simple to do.  Just set it up as shown here.

https://community.servicenow.com/community?id=community_question&sys_id=5ea11b6ddbdcdbc01dcaf3231f96197e

View solution in original post

10 REPLIES 10

Mark Stanger
Giga Sage

This article shows how you can do this for all sorts of things.

https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

As long as 'u_director' and 'u_director_name' reference the same table, you should be able to simply place this as the default value in the 'Default value' field on the 'u_director' field dictionary.

javascript:gs.getUser().getRecord().getValue('u_director_name');

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Lisa,

So you want the director name field which is a reference field to have default value with the logged in user's director.

set it in default value at dictionary level. is there a field on user table which stores the director

javascript:gs.getUser().getRecord().getValue('<userFieldStoringDirector>');

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Lisa_Wiegmann
Giga Guru

Mark,

I'm getting an error, "Error Message Illegal access to method getRecord() in class com.glide.sys.User".  Both of my fields reference the sys_user table. 

 

I will also add that the u_director_name field is hidden until a different field is set on the Change Request.

Please post screenshots of the error message on the form...as well as your dictionary entry showing the default value.