- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2015 09:21 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 05:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2015 05:46 AM
Jan/Paul,
Thanks for your answers/comments. Our team will review, and I'll post our decision asap.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 05:18 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2018 01:42 PM
I came across this thread while doing some research on this, as I was trying to call some protected script includes from a scoped app.
This solution is genius because you can call a global API from a scoped one, and then using that API call a global script, which effectively bridges the scope gap.
This method also exposes other similar possibilities, like calling a global workflow with a script activity from a scoped app script.
Or inserting a scoped event, and then having a global event script action. Since ServiceNow wants scripts that are scoped to locked down from calling each other sometimes, they're more likely to try and lock down these workarounds rather than exposing a proper way.