How to get application scope in an Experience page?

thomaskennedy
Tera Guru

I have a data broker that returns some details about the most recent import set created for a given Scheduled Data Import, so I can configure a List control to display its content. I want to pass that broker the name of the import, but also the scope, so I do not get information back on some other import set. So as a first step I pass in the name of the import:

 

[
{
"name": "scheduled_data_import_name",
"label": "Scheduled Data Import name",
"description": "Name of the Scheduled Data Import for which you want the most recent import set",
"fieldType": "string",
"mandatory": true,
"defaultValue": ""
}
]

And in the data broker script I tried to use gs to get the application scope:

var gr = new GlideRecord("scheduled_import_set");
//gr.addQuery("sys_scope", gs.getCurrentApplicationScope());
gr.addQuery("name", input.scheduled_data_import_name);
gr.setLimit(1);
...

But when I do that I get an error mesage in the log saying getCurrentApplicationScope is not allowed here.

So my next thought was to pass in the scope from my page. But I do not see scope available on the properties, only app id.

So how can I get the current scope into, for example, a client state variable so I can pass it as an additional param, to be sure I get the right import set?

I suppose I could set up a Tranform data resource to return it, but that seems roundabout.

 

 

5 REPLIES 5

Shivalika
Mega Sage

Hello @thomaskennedy 

 

This is expected. Gs object is not allowed to be used in data broker. 

 

Data Brokers run in the GraphQL execution context

 

Unlike standard server-side scripts, Data Brokers are executed within the GraphQL engine, which restricts access to certain global objects like gs to maintain security and prevent unauthorized access to sensitive data.

 

Alternative solution - use below script 

var session = GlideSession.get();

var userScope = session.getClientData("current_app_scope");

gs.info("User's current scope: " + userScope

);

 

OR 

 

Store the application scope somewhere and then just get it here. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwN

eEISQCY

Thank you! I figured there was a very good reason for this behavior.

I'm going to hard code the scope in a client state variable and pass it as a param to my broker, and come back to this later to see if there's a way to avoid hard coding.

 

That script throws an exception when I run it in my scope. It returns null when I run it in global.

 

 

Hello @thomaskennedy 

 

It's great that this helped you. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway 🙂, so that this thread can also be closed. 

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Kieran Anson
Kilo Patron

gs.getCurrentApplicationId() might be what you want in a scoped application