Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Community Alums
Not applicable

/* Gets the currently Open Update Set */
UpdateSetUtil.prototype._getCurrentUpdateSet = function() {
var functionName = "_getCurrentUpdateSet";
var sid = new GlideUpdateSet().get();
this.gsLog.logDebug(functionName + ": sid = " + sid);
var currentUpdateSet = new GlideRecord("sys_update_set");
currentUpdateSet.get(sid);
return currentUpdateSet;
};

/* Gets the name of the currently Open Scope */
UpdateSetUtil.prototype._getApplicationName = function() {
var functionName = "_getApplicationName";
var currentUpdateSet = this._getCurrentUpdateSet();
var app = currentUpdateSet.getDisplayValue(application);
return app;
};