I have a scripted REST API to create REQ/RITM of a particular catalog, how do I modify REST Request Body before I create REQ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:10 AM
I have a scripted REST API to create REQ/RITM of a particular catalog, how do I modify REST Request Body before I create REQ?
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:55 AM
Hey Chuck,
I have a catalog item which has Variable Set with fields like (Requested_For, Phone, Line manager, cost center )....the third party tool will send the "name" of "Requested for".
Eg..
{
"sysparm_quantity":"1",
"variables":{
"s_name":"PhotoShop",
"e_ref_num":"SOF1234",
"requested_by":"Daileena Gomes",
"requested_for":"Joel Dsouza",
"phone_number":""
}
}
and in scripted rest API I am pulling Requested for SYS_ID and phone , line manger details from SYS_USER and want to set this values in REQUEST BODY...and then hit "cart.orderNow(request_body);"
currently the Scripted REST creates RITM and populated VARIABLES , however the REQUESTED FOR and REQUESTED BY will get populated only if I pass SYS_ID.
I am using code in "Buy Item " resource of Service Catalog REST API as baseline.
If not possible in Scripted REST, I am thinking of setting it once REQ is created via Business Rule, however need to check various ways I can do this and then use the best one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 11:15 AM
Did you ever get this figured out DJD? We are running into a similar situation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 10:28 AM
Hey,
you can access incoming message body using below
var request_body = request.body.nextEntry();
var requestVar = request_body.variables;
Then, you can modify variable values in cart using below.
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(itemId);
cart.setVariable(item, "requested_by", req_by);
cart.setVariable(item, "requested_for", req_for);
cart.setVariable(item, "line_manager", requestedForDetails[0]);
cart.setVariable(item, "cost_center", requestedForDetails[2]);//not working not sure why
cart.setVariable(item, "phone_number", requestedForDetails[1]);
cart.setVariable(item, "location", requestedForDetails[3]);
hope this helps.
Regards