After upgrade from NY to Paris, Using Cart API with Guest User fails if Catalog Item doesn't have User Criteria set

codycotulla
Tera Guru

Hi,

Question: Is there a system property or something that prevents the Guest user from being able to create a request using the Cart API?

Situation

After upgrading from NY to Paris, I find that when Guest is the active user and I try to use the Cart API to create a request. I get a failure message. 

com.glideapp.servicecatalog.exceptions.CartException: Your cart has item(s) no longer available. Please remove XXXXRequestTitleXXXXX from cart to continue with the checkout.

If I add a User Criteria record allowing any user (no restrictions) to the Available For related list, then the call succeeds.

I found the problem when inbound email actions failed after upgrading. Then I created an ATF test using script taken from the Inbound email action: 

Testing Done

I created an ATF test that calls the API using the same code that is in the inbound email action.

(function(outputs, steps, stepResult, assertEqual) {
    // add test script here
    try {

        var message = "";

        // set the "success" variable to false if there is an expected result in the script
        var success = true;

        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId); //calling the cart API  
        //var cart = new Cart();   //calling the cart API  
        var item = cart.addItem('21870631db98ff00660658b8dc96199b'); //sys_id of the catalog item I want to fire  
        cart.setVariable(item, 'mm_reason_for_request', 'Unknown - Email');
        cart.setVariable(item, 'sc_requested_for', gs.getUserID());
        cart.setVariable(item, 'sc_requested_for_userid', gs.getUserName());
        cart.setVariable(item, 'sc_requested_for_email', gs.getUser().getRecord().getDisplayValue('email'));
        cart.setVariable(item, 'sc_requested_for_manager', gs.getUser().getManagerID());

        var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object.   rc = the request object  

        message += "\nCart rc: " + rc.sys_id;


        if (success) {
            stepResult.setOutputMessage('Success!\n' + message);
            return true;
        } else {
            stepResult.setOutputMessage('Failure!\n' + message);
            
			return false;
        }

    } catch (e) {
        stepResult.setOutputMessage('Failure!\n' + e + message);
        return false;
    }




})(outputs, steps, stepResult, assertEqual);

Test Results

I find that the test succeeds in the following cases:

  • Impersonate an existing user with a role.
  • Create a user with no roles.
  • Impersonate the Guest User and add a User Criteria to the Available For 

Fails in this case;

  • Impersonate the Guest User (no user Criteria on the catalog item)

Let me know if you have any questions.

Any help would be appreciated,

Thanks,

Cody

1 ACCEPTED SOLUTION

codycotulla
Tera Guru

I opened a Hi ticket for this, and they confirmed that with Paris if you want to allow the Guest user (an unauthenticated user) to use the Cart api to create a catalog request, you need to make the catalog item available for any user by adding a User Criteria record with no-restrictions.

View solution in original post

12 REPLIES 12

codycotulla
Tera Guru

I opened a Hi ticket for this, and they confirmed that with Paris if you want to allow the Guest user (an unauthenticated user) to use the Cart api to create a catalog request, you need to make the catalog item available for any user by adding a User Criteria record with no-restrictions.

I tried this, but unfortunately it is not working for me

Cody - this helped solve my problem, thank you!

For those that might not know, there should be an "Any User" criteria group you can add to the Catalog Item.

find_real_file.png

As an added word of caution, when I edited the "Available For" to include "Any User", the next item ordered triggered a backlog of requested items. I did this in our dev instance, because I was concerned it would send out a boatload of backlogged emails. Considering the outbox had 97 send-ready messages, I'm glad I did.

Many ServiceNow clients may not have the luxury to do this - our instance doesn't send out a lot of emails, so I temporarily put our Production instance in "debug" mode and sent all the messages to my email address. If anyone has a better way of doing this - please let me know. I considered temporarily disabling email, and deleting them in the "send-ready" state.

Hi @Mitch Fleischman @Ankur Bawiskar  @Pradeep Sharma

Can you guys please help me out, I am facing the same issue I have added the user Criteria as mentioned in my order guide but still I am getting the error.

I need to resolve this issue on Priority bases.

Any Help will be Appreciated!

Thanks