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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 01:12 PM
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(); |
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 01:18 PM
Hi Ravio,
Your have to query sc_request table to update fields. Please refer sample script.
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()) {
//set values here.
parentRequest.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 01:16 PM
Sure this is all fine, but unfortunately, after the request is placed, the approving manager has already been selected. Changing the requested_for AFTER is no longer applicable.
Any ideas on how you can specify the requested_for in cart before the order is placed?
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 08:48 PM
Are you requested_for and opened _by form the web service? What details are you getting from web service?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 06:53 PM
In order to change the requestedfor value on request, you can create an onbefore business rule on sc_request table
on before
Conditions: Item is <slect your item>
Script:
var gr= new GlideRecord("sc_request");
gr.get(current.getValue("request"));
gr.requested_for=current.variables.requested_for;
gr.update();