ServiceNow Cart API in Scoped Application

Arun Chauhan
Giga Contributor

I have a scoped Application and I want to create the Service Ticket using the Cart API on the Fuji instance. I have following code written in my Script Include inside Scoped Application:

var cartId = gs.generateGUID(null);

var cart = new global.Cart(cartId);

This result in error says:

java.lang.SecurityException: Illegal access to private script include Cart in scope rhino.global being called from scope x_my_app.

The Cart is not available in the private scoped application. I changed the "Accessible from" to "All Application scopes" on Cart Script Include and it started working.

I want to ask, Can I modify my script to make it working without changing the "Accessible from" field on Cart Script Include.

6 REPLIES 6

Daniel Draes
ServiceNow Employee
ServiceNow Employee

That would actually be a very good question to ask our developers


I sometimes struggle also with the way they fence global things from scoped apps. Maybe you should raise a HI ticket to get them to look at it.


Wesley Breshear
Tera Expert

Hi Arun,



Did you get an answer or determine how to resolve?   My Script Include is now failing as well with the same command you have, however, haven't been able to figure how to capture the error message (if there is one), but pretty positive it breaks at the same code line.   I am using scoped application as well.



    if (!ritmRecord.next()) {


            gs.info('EKCM: Create Renewal for '+ekcmRecord.name);   //This line gets recorded to the System Application Logs.


    // var cartId =   gs.generateGUID(); //GlideGuid.generate(null);   //Was not needed and was remarked out a while ago.


    var new_cart = new global.Cart();   //Pretty sure it is error-ing out on this line.


              gs.info('EKCM: Create Renewal #2 for '+ekcmRecord.name);   //This line fails to record to the System Application Logs.



-Wesley


Hi Wesley,



We had a interaction with the ServiceNow team and as per discussion, currently you can't access the Cart API from the scoped application scope. Only way to implement this either you change the "Accessible from" field to "All application scopes" on Cart Script Include OR write your script in the global scope to user Cart API and refer it in your scoped application scope. I am using the later approach as ServiceNow Admin will not allow you to change the scope of any System Script Include.



ServiceNow placed this incident in their system and they are planning to come with a solution in the Helsinki or Later version.


Update and what fixed my issue.  



While my script was set to use "All application scopes", the original ServiceNow (core) script called "Cart" was not.   It was set to "Use this application scope only".   Once I changed the "Cart" script 'Accessible from' field to "All application scopes", my script began to work.   Arun had the correct answer, but I missed that he was saying to modify another script with ServiceNow.  


Cart.jpg



Thank you Arun,



-Wesley