How to get current scope in script

Christian Walli
Tera Contributor

Hi there,

the ServiceNow user interface has a picker in the top bar where the active scope can be selected.

Is there any way to get that current active scope in a script (server or client side)? It doesn't matter if I get the name or the sys_id of the scope, either one would be ok for me.

1 ACCEPTED SOLUTION

stannard95
Kilo Expert

I may have found a better solution than the accepted one.

 

gs.getCurrentApplicationId();

 

This returns the 'sys_id' of the current the application the user is in.

Use this sys_id to GlideRecord into 'sys_apps' and you'll get the name of the app.

 

 

var currentApp = gs.getCurrentApplicationId();

var gr = new GlideRecord('sys_app');

gr.get(currentApp);

View solution in original post

10 REPLIES 10

Christian Walli
Tera Contributor

Thanks for the suggestions.

The method gs.getCurrentScope() always returns the scope in which the script include is defined. I need to get the scope that the user has currently selected in the scope picker.

 

Then, I am afraid there is no easy way to achieve it.

Currently, I couldn't find the table which stores all the application with the current status but there is an API which can return you the current scope which user has selected.

 

https://instancename.service-now.com/api/now/ui/concoursepicker/application

Try hitting this one and get the current scope in xml/json format.

You can then parse the response to see the current scope.

 

Christian Walli
Tera Contributor

Thanks Gaurav,

I've been digging around a little bit inside that REST API story. It's seems that the required authentication setup is out of scope for the app we're building.

Anyway it's good to know how this could be done in case we absolutely must do it 🙂

stannard95
Kilo Expert

I may have found a better solution than the accepted one.

 

gs.getCurrentApplicationId();

 

This returns the 'sys_id' of the current the application the user is in.

Use this sys_id to GlideRecord into 'sys_apps' and you'll get the name of the app.

 

 

var currentApp = gs.getCurrentApplicationId();

var gr = new GlideRecord('sys_app');

gr.get(currentApp);

In fact you did!

Thanks for your solution - it does what I need and is easy to use.