Default value for a catalog variable using logged in user details

jonathangilbert
Kilo Sage

Good Morning

 

I am trying to set the default value of a catalog item variable using the current logged in user details.

I can see this seems to be the common way of doing it :-

 

javascript:gs.getUser().getRecord().getValue("location");

 

But I want to populate the variable with a value from the location table not just the name of the location. How to I expand the line of script to pull field values from the location table?

 

Many Thanks

1 ACCEPTED SOLUTION

jonathangilbert
Kilo Sage

 I have actually resolved the issue using the "Auto-Populate" option on the variable.  I had tried this initially and it did work, hence why i asked on the community. I then deleted the variable and recreated it and set the auto populated value again and it works as expected.  Thank you all for you valued assistance

View solution in original post

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @jonathangilbert,

 

You can use either

javascript:gs.getUser().getLocation();

OR

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

 

It will brings value from location field in user table which is referenced form Location [cmn_location] table only.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi Sagar,

 

That is what I have, I wish to populate the value from the locations table, i.e fieldx, how do you expand the script?

 

Many Thanks

Danish Bhairag2
Tera Sage
Tera Sage

Hi @jonathangilbert ,

 

I am not sure if that is possible. You can either use a on load script to fetch location information using GlideAjax call or u can directly call a script include in the default value tab.

 

Please mark my answer Helpful & Accepted if it addresses you issue.

 

Thanks,

Danish 

 

jonathangilbert
Kilo Sage

 I have actually resolved the issue using the "Auto-Populate" option on the variable.  I had tried this initially and it did work, hence why i asked on the community. I then deleted the variable and recreated it and set the auto populated value again and it works as expected.  Thank you all for you valued assistance