how to set requested for and opened by in a request using the cart API?

Ravish Shetty
Tera Guru

Hi all,

We get request details from an external system using web service.

These details include opened by and requested for.

I am creating requests using the cart API.

How do i set the requested for and opened by using these details?

Here is the script that i use

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(gs.getProperty('jsb'));//963a960e4f28e200cf15c98e9310c7e4
cart.setVariable(item, 'request_name', request_name);
cart.setVariable(item, 'request_details', request_details);

cart.setVariable(item, 'opened_by_email', opened_by_email);
cart.setVariable(item, 'requested_for_email', requested_for_email);

var rc = cart.placeOrder();
9 REPLIES 9

The process proposed totally makes sense,however, when I created the business rule, and ran the script, it generated 122 requests and never fulfilled what it was supposed to, set the requested for field.



Maybe I missed something....


Created before BR on sc_request,   added code in advanced, set to insert, however there is no ITEM in sc_request condition options, so set condition to run if record created by System Admin, which is what my script runs as.


Tim Grindlay
Kilo Sage

Just spamming my answer in the posts that were asking the same question. Hope this helps someone.

Take a look at the script includes SPCart. I mentioned it's use in this post years ago, but found a better way after revisiting the requirement.

var cat_item = ""; //Sys ID of the catalogue item you're adding
var opened_by = ""; //Sys ID of your opened by user
var requested_for = ""; //Sys ID of the requested for user



var cartId = GlideGuid.generate(null); //Generate the sys ID for the cart
var cart = new SPCart(cartId, opened_by); //Create the cart with the opened_by user
var item = cart.addItem(cat_item); //Add the item to the cart

//Define your variables 
//cart.setVariable(item, <variable name>, <variable value>);

cart.setRequestedFor(requested_for);

var SCrequest = cart.placeOrder();

I did not know about SPCart as I've used "Cart" forever...SPCart and allowing me to use "setRequestedFor" are exactly what I was looking for!


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Mohan Mallapu
Kilo Sage

HI Alll,,

Could anyone help me to set the requested for variable in the catalog item through CartAPI by using userid not with sys_id of the user.??

Thanks in advance..

This will find the sys_id of the user if you input the user ID, is that what you need?

var userID = ''; //User ID to look up

var userSysID = gs.getUser().getUserByID(userID).getID(); //return the sys_id of the user