How to set requested for in RITM using Cart APi is it possible?

Gowtham Kodali
Tera Contributor

I am using Cart api to set Requested_for field for different users,but still the requested for is showing my name only

is there any way to set the requested_for by using Cart API

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Gowtham Kodali 

Unfortunately you cannot set any fields of REQ or RITM using Cart API

the only way is to get the REQ sys_id and then set the value

sample script below

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();

var reqRecord = new GlideRecord('sc_request');

reqRecord.get(rc.sys_id);

reqRecord.requested_for = 'user sys_id you want here';

reqRecord.update();

Regards
Ankur

View solution in original post

16 REPLIES 16

@Gowtham Kodali 

if you have the variables in the excel file then I would suggest parse the excel row by row and then use the above script to create those many RITMs and REQs.

Regards
Ankur

Phonsie Hevey1
Tera Expert

A colleague of mine told me how to do this.

var cart = new Cart(null, sys_id_of_requested_for);

That's working for me now in Paris. If you update the REQ after it's created any notifications seem to go out to the two users so I think this is a better way of doing it.

Kind regards,

Phonsie

Hi,

Are you referring to this?

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId, sys_id_of_requested_for);

Regards
Ankur

Hi Ankur,

Yes, that would be the same thing, but different from the answer marked as correct on this thread.

Kind regards,

Phonsie.

Thank you for sharing