Get current Application scope or Update Set via Scripted API call

Andre Kosak
Tera Contributor

Hello Community,

I am trying to get the current application scope of a user via Scripted API call, but the platform behaves unexpected. Here is my Scripted REST resource:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {


	//var session = gs.getSession();
	//var appID = session.getCurrentApplicationId(); // Illegal call
	var appID1 = gs.getCallerScopeName(); // always "rhino.global"
	var appID2 = gs.getCurrentScopeName(); // always "rhino.global"
	var appID3 = gs.getCurrentApplicationId(); // always "global"
	var appID4 = new GlideUpdateSet().get(); // Always "066f396ab96013006517ce7df7ee46b2"
	
	gs.info('appID1 '+appID1+'\n appID2 ' + appID2 + '\n appID3 '+appID3 + '\n appID4 '+appID4);

	// Return current scope of user session

	response.setBody({'response':'Application ID should be here'});
	response.setStatus(200);
		
})(request, response);

In comments you see the value that variable gets every time, disregarding of current Application scope selected.

How do I test it:
I am logged in with my "admin" user and switching the application scope from Global to any other. Then sending a request to the Scripted API endpoint authentificating myself with the same user. I assuming to get the current Application ID (or name) of my user session. But the methods listed above returning always same values.

Getting the sys_id of current Update Set would also help me, but new GlideUpdateSet().get() returning the same value all the time (sys_id of Default Update Set).

Any ideas?

1 ACCEPTED SOLUTION

DirkRedeker
Mega Sage

Hi

if you want to find out, which is the current update set of any given user, you can look into the "User Preferences" [sys_user_preference] table. See screenshot below:

The "Value" column contains the "sys_id" of the Update set, which is the current setting of the given user.

find_real_file.png

 

So, fo the "System Administrator", it is currently (see screenshot below):


find_real_file.png

 

Looking into the Update Sets table, and searching for the Sys_ID, you will find the update set, that the given user currently selected:

find_real_file.png

 

Let me know, if that answers your question and mark my answer as correct and helpful, please.

 

Thanks & BR

Dirk

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

In which scope the scripted rest api is created?

I have one scripted rest api in custom scoped app and when I test it is giving below results

appID1 x_30520_ank
appID2 x_30520_ank
appID3 global

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

The scripted api has been created in Global.
My intension is to get the Application Scope of current user session, not the scope of the scripted rest api...

Hi Andre,

User record doesn't belong to any scope i.e. you cannot have scope defined for sys_user table as the application field is not present on sys_user table

So any user who is present in sys_user table is always created in global scope

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

that is not what Andre was asking though.

It's about the user session, not the sys_user itself.