Show widget if logged in user is from specific country

Julius28
Tera Expert

Hi Community,

 

I have question regarding server side scripting regarding my custom widget.

Since I'm quite new to ServiceNow and scripting I have obstacle to figure out how to get to solution.

I have cloned icon link widget, had done UI and so on but now I need to show it only for users which are from specific country.

In my case people with have country code "SE" should be only able to see the widget, others shouldn't.

Now I understand I need to modify HTML template and server script right?

Basically if user is SE, then true otherwise false and if it returns true, then on top of html code I need to write conditions on first ng-if = SE = true then show something like this.

 

Bellow is base server side script in which I'm stuck. Can you please guide me to right direction by giving tips so I could achieve my goal?

 

(function(){
var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
var location = gs.getUser().getLocation(); // Did i add this line correctly, should it even be there?
if (location == 'SE') // can I continue to write this if?, If yes, then how can I proceed?

})();

 

 

Any help highly appreciated. Thank you!

2 REPLIES 2

SuhasPSalunkhe
Kilo Guru

You can use following things -

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

Will look for the script include as well once.

 

Also you can directly glide the sys_user table based on user id and you can get location and location code.

hello,

Thank you for looking into this.

Did not quite understood your suggestion, can you please explain a little bit more?