Setting default value of catalog item variable to users country

kevinray
Giga Expert

Hello.

I have a variable in my catalog item called primary_spending_location.

I want this variable to default to the submitter country of record.

I used the "Default Value" field on the variable and set to

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

This does not work. The field just remains blank. (i have ensured the logged in user has a value in the country field on their user record)

I've tried javascript:gs.getUser().getLocation(); //This works just fine

I've tried javascript:gs.getUser().getManagerName(); // This works just fine.

I've tried most of the items found here: http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0 but COUNTRY does not work.

I've tried to make the field Single Line Text, and it's still blank, but the others populate the field just fine

I've tried to make the field what I actually want it to be (a Lookup Select Box to the cmn_location table "country" field), and it just always defaults to the first one in the list

Any ideas?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Kevin,



I did a quick test and gs.getUser().getCountry() returned the value in the Country code [country] field on the user record for the logged in user. If you've just added the value to the field for testing you'll need to log out and back in or reimpersonate in order to use the value on the user object. Also note that it should return the country code, so US or UK.



Also, does this happen to be in a scoped application?


View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Kevin,



I did a quick test and gs.getUser().getCountry() returned the value in the Country code [country] field on the user record for the logged in user. If you've just added the value to the field for testing you'll need to log out and back in or reimpersonate in order to use the value on the user object. Also note that it should return the country code, so US or UK.



Also, does this happen to be in a scoped application?


Hi Brad,


No, this is a catalog item in Global.



This is my ootb personal dev instances, so maybe there is something wrong with it. but it's not working



Set default value


find_real_file.png


Tried to look up by sys_id and name both


find_real_file.png



This is what i get when it's a look up


find_real_file.png



The country's are still a choice



find_real_file.png




When i make it a single line text field instead of a lookup select box, it's blank.find_real_file.png



you can see for yourself here if you'd like


ServiceNow


id: abel.tuter


pw: test


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hmm...I configured that in an instance both ways and it works, even though for the lookup select I think the value and label should be the country field. I would check your browser console for any errors when you load the catalog item.


Thanks Brad. I decided to try this out directly in one of my sub-instances, and it works just fine. Something wrong with the Personal Developer instances that doesn't like this function. (even wiped out, restored and upgraded...still doesn't work) What a waist of time!!



Thanks for your time. It helped a lot!