How do I call a global "This application scope only" script include from my scoped app

maynartt
Kilo Guru

I realize that because script include SLACalculatorNG is in the global app, and its Accessible from value is "This application scope only", when I try to call it from a business rule created within my scoped app via the following script lines:

var slaCall = new global.SLACalculatorNG();

slaCall.calculateSLA(current,false,current.end_time);

It returns this error:

Illegal access to package_private script include SLACalculatorNG: caller not in scope rhino.global

However, does anyone know of a way that I can use SLACalculatorNG as-is from my scoped app?

Thanks!

1 ACCEPTED SOLUTION

maynartt
Kilo Guru

All,


In summary, since we can't execute the out-of-the-box process directly from a business rule call, we worked around that restriction by calling the same process, but doing it as if we manually built what we need to execute and running it via System Scheduler, Scheduled Jobs, Scheduled Jobs (creating a new Schedule Item that runs once).



Here's what we ended up doing:


Created a service account User record and set it up as a property within our app.


Created an async business rule on the record we're trying to update (executes on insert and update) with the following in the script:


var request = new sn_ws.RESTMessageV2();

      request.setEndpoint('https://' + gs.getProperty('instance_name') + '.service-now.com/api/now/table/sys_trigger');


      request.setHttpMethod('post');



      var user = gs.getProperty('our_app_name.service_account');


      var password = gs.getProperty('our_app_name.service_account_password');


      request.setBasicAuth(user,password);


      request.setRequestHeader("Accept","application/json");


      request.setRequestHeader('Content-Type','application/json');


      request.setRequestBody("{'name':'Calculate Task SLA','script':'var taskSLA = new GlideRecord(\"task_sla\"); if (taskSLA.get(\"" + current.sys_id + "\")) { new SLACalculatorNG.calculateSLA(taskSLA, false, taskSLA.end_time); }','trigger_type':'0'}");


      var response = request.execute();



We'll leave this in place until ServiceNow decides to make the process available to all app scopes.


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Tor,

 

 The only way if you want to call that script include from the scoped app would be to change the Accessible value from "This application scope only" to "Available to all scopes". 

 

Thanks, Pradeep.   Unfortunately, there are a couple of reasons why we don't think we can do that.



1) we plan on packaging our app to install at other instances.   We're trying to avoid special installation instructions whenever possible.   We'd have to manually make that change before each installation.


2) the script include has a protection policy of read-only, so even when I switch my app to global, I can't change the value in accessible from.  



I was also working with ServiceNow support on this, and they recommended submitting an enhancement request to allow this script include to be accessible from all app scopes.  


jancaasi
Mega Expert

Hi Tor,



One quick question, is it possible to copy the entire script SLACalculatorNG and then create a new script in the Script Include?


The SN Nerd
Giga Sage
Giga Sage

From a design perspective, I've been putting all calls to global scoped script includes that can't be called from within an application scope into a "Global Dependencies" script include in a 'Application X - Global Dependencies" application,



As ServiceNow opens them up or I find a workaround, I take them out and incorporate them back into the application.


When packaging the application, I then include special instructions "Please import external SI".



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022