Variable default value g_user object

mrswann
Kilo Guru

Using g_user to populate the variables with default values seems difficult.

Do I have to resort to having different record producers to different users , tied to templates to populate values ? as the gs.user object in template seems more dependable but this doesn't seem great from a maintenance POV ?

users with roles should be able to make requests for people other than themselves , those without are just for themselves.

thus some custom user fields should be prepopulated and locked down . I can present different items to different users but concerned re maintenance.

i have another thread about locking down based on g_user and some work to do thru cat UI policy / client script... I have a separate requirement here using g_user in variables

or is it gs.user for default values for rec producers   as they still   load from server not client?

Hope not too n00bish as I've tried reading docs and searching and experimented to no avail

many thanks

4 REPLIES 4

Jace Benson
Mega Sage

Can you be more clear what you are trying to do.   Can you share some code samples and where they are?


Sounds like you are using the session data and trying to use it in ui policies and client scripts;


http://wiki.servicenow.com/index.php?title=Session_Client_Data#gsc.tab=0


TThanks I'll try..



When end record producer loads I want it to prepopulate three fields based on the user...



name, email and company



the first two fields are custom fields we already populate manually but now are opening up for users to raise their own changes. In most cases going forward this will cause duplication against end created_by and opened_by as it will be the same person. We don't currently populate company but with the portal coming on line we want to be able to discriminate requests by the vendor.


I expected putting "g_user.username" into default value of the variable would suffice for name, and .email and .company for the others



i previously had success submitting the record producer against a template, then the template contained gs.user().companyid() and etc but then I would need to discern a record producer for non roled users vs a roled user on the basis we have certain roles raising changes on behalf of others




does this help?




i Think we probably need to reconsider what is actually necessary but I wanted to do so knowing what is really possible , if that makes sense



i will review your link as I dont recognise the page title from memory


Yes, okay so you're trying to use the default value of a variable to access g_user.   g_user is only client-side available.   Depending on the type of field try this;



If it's a reference variable linked to sys_user try this in the default value as it will return the logged in user's sys_id.


gs.getUserID();



If it's a string variable, try this in the default value as it will return the user's name.


gs.getUserDisplayName();



Heres more documentation about using this.


Default values on variables use Server-side javascript.   GS is a server side available object.


GlideSystem - ServiceNow Wiki


It's this bit I think I needed to be clarified..,


Default values on variables use Server-side javascript.




im starting to understand and put it all together! So the record producer is loaded and populated using server side actions, so this requires gs object calls. Once loaded all behaviour is client, for things like catalog UI policy and scripts, but there are ways to combine using business rules and script includes and so forth. (Complex!)


Once passed from   the client back during submission , when it hits the assigned   template within record producer it uses gs again...



my summary is probably not so concise but I will put it to practice and thank you for your time and assistance