How to set/enforce the fields on Request and Request item table using CartJS API

Thenmozhi5
Kilo Explorer

Hi,

We are using custom checkout widget with CartJS checkoutcart API to create Requested Item and Request. During creation we want to update few fields on Request and Request item table. Do we have any functions in CartJS to update the fields on Request and Request item ?

Regards,

Thenmozhi

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Thenmozhi

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate answer as correct & helpful to close the thread.

If not, please let us know if you need some more assistance.

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use the object which is returned from the placeOrder() function to set the request values

The API only allows you to set variables, so the standard way to populate fields is to use the request sysid that the cart api gives you then perform query & set Req fields and then the requested items associated with the request and populate field values.

refer below sample script

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('4054428fdb151f0097679ec6db9619c0', 1);

//fill in the variables on the request item form
cart.setVariable(item,"u_requested_for", "e80edd6edbec6bc097275e25ca9619a4");
cart.setVariable(item,"contact_number", "0");
cart.setVariable(item,"assignment_group", "87ec1c342b2e71406c487fb5a8da1524");
cart.setVariable(item,"application_service", "cdedfbcedb0f9744c291c170ba9619a7");
var rc = cart.placeOrder();

rc.requested_for = 'sys_id';

//set your fields here for request


rc.update();

var ritm= new GlideRecord('sc_req_item');
ritm.addQuery('request',rc.sys_id);
ritm.query();
while(ritm.next()){

ritm.short_description=email.subject;
ritm.<field name>=<value>;
//set your fields here for RITM

ritm.update();

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate answer as correct & helpful to close the thread.

If not, please let us know if you need some more assistance.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Shilpa Gaikwad
Giga Contributor

Hi Ankur,

We have added user defined fields to the request and requested item table. Does the API have an option to set user defined fields(custom fields) for the request and requested item? 

Looking forward to your response.

Regards,

Shilpa

Hi Shilpa,

No you cannot set custom fields directly using Cart API.

You will have to follow approach mentioned above.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader