How can I auto populate user location information in service catalog variable?

itspezi1
Tera Guru

Hello team,
How can the location be automatically displayed by the user in the catalog item? What type do I have to add?

Many thanks

 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

So you'd create a reference variable that points to the location table, then you can set the default value of that variable to be:

find_real_file.png

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

Which will automatically place the location of that user in that field for you.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

10 REPLIES 10

After looking into your attached file, Location filed in not configured on form,

 

Right click on header menu -> configure -> form layout -> then bring location field from available to selected.

Then location field will be on user form.

find_real_file.png

I cannot save the address in the user view. I am currently using the Paris Release in my instance. Does any of you have the same mistake? The address can be selected, but after saving the address is gone again.

Hi,

That's because the Location is dependent upon the Company. Here is the dictionary dependency tab within the location field showing that:

find_real_file.png

So you'd want to either remove company from that field and save...

Or...

Choose a location that has an appropriate relationship to the Company.

Meaning...right now, when you select a location, it's not related to the company set for the same user, so when you save, it gets removed.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Dhananjay Pawar
Kilo Sage

Hi,

Do you want currently logged-in user location? If yes then go with Allen's solution.

If you have user variable and you want selected user location then you need to have callback functionality in place or Client script and script include combination to fetch location and set to variable.

Thanks,

Dhananjay.

Hi, 

I'm trying to accomplish something similar. 

Do you have an idea of what would need to change in this script for it to work?

 

https://community.servicenow.com/community?id=community_question&sys_id=d7b8d5461b667c90d46b62c4bd4bcbe8&anchor=answer_c70d1182db6274903dd13ca8f4961930