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

Gaurav Bajaj
Mega Sage

Hi,

I think you are looking for this method.

 

gs.getCurrentScopeName()

 

Please mark it correct/helpful based on the response.

Thanks
Gaurav

I want to change the scope in the middle of the script and come back to original scope after a certain action is performed. Can this all be done in scripting? Thanks

Hi @amol_joshi ,

You can use Script Include for the same where you can define the script in the scope where you want to perform action and return the value. Changing scope I can say isn't a best practice/recommended.

Trupti6
Tera Expert

Hi,

Try this code,

var getCurrentScope=gs.getCurrentScopeName();
gs.print(getCurrentScope);

 

 

Thanks,

Tripti.