Set Parent Request Properties from Cart API

mspeers
Kilo Contributor

I'm trying to create a request item from an inbound action.   I can do this and set variables on the item without issue.   It also creates the parent request, which is desirable as well. I'm trying to set properties (like the short_description, description, etc) on the parent request from the inbound action without success, however.  

  1. Can this be done through the cart api?
  2. Is there a good "object browser" for the Cart object so I can examine all that it has & does?   The wiki article for the Catalog api doesn't show how to achieve this.

Thank you,

Michael S.

4 REPLIES 4

josh_nerius
ServiceNow Employee
ServiceNow Employee

Hi Michael,



If you're using something like the example code shown here: Service Catalog Script API - ServiceNow Wiki, you can update the parent request after placing the order. Example:



var rc = cart.placeOrder(); // <-- rc is the sc_request GlideRecord


rc.short_description = 'my short description'


rc.update();



Since rc is just a GlideRecord, you can update fields as needed.



The 'Cart' object is a Script Include, so you can explore the available methods by searching for 'Cart' in the Script Include table.


Hi Josh,



I am using something like the article you posted.   I have tried this and the commented out stuff to get the cart again.   Neither is saving to those fields:



var rc = cart.placeOrder();


rc.short_description = "Employee Termination";


rc.update();


// var cartGR = cart.getCart();


// cartGR.short_description = email.subject.toString();


// cartGR.description = email.body_text;


// cartGR.contact_type = 'email';


// cartGR.update();



The request and the request item are created and are linked together. But the request properties are not set.   This is in an 'Inbound Action'.  


mspeers
Kilo Contributor

Worked when placing the order then immediately querying for the request again and editing it:



var rc = cart.placeOrder();


//Then query for the request and edit


var parentRequest = new GlideRecord('sc_request');


  parentRequest.addQuery('number', rc.number);


  parentRequest.query();


  if (parentRequest.next()) {


  parentRequest.contact_type = 'email';


  parentRequest.short_description = "Employee Termination";


  parentRequest.description = body;


  parentRequest.update();


  }


The above simply doesn't work!