- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 07:29 AM
I have a scheduled job that will run every morning 6 am to review current contractor profiles, and if they are expired, auto generate a service request for termination.
Everything works fine, just a question.... When I generate the service request using the following:
var cart = new Cart();
var item = cart.addItem("b151029edb110f00aa103c8f9d9619fd"); // System Termination
cart.setVariable(item, "sys_requested_for", usr.name);
cart.setVariable(item, "sys_delivery_date", gs.now());
cart.setVariable(item, "sys_comments", 'System generated termination request for expired contractor account.');
cart.placeOrder();
It generates the request fine, but only populates the RITM variables. Is there a way to populate the Request fields, specifically the "requested for" field?
In order to follow the correct approval process, I need to be able to get this set to the same "requested for" as the RITM field.
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 07:39 AM
You can get the 'sys_id' of the order created and use that to query the 'sc_request' table to update those details:
var cart = new Cart();
var item = cart.addItem("b151029edb110f00aa103c8f9d9619fd"); // System Termination
cart.setVariable(item, "sys_requested_for", usr.name);
cart.setVariable(item, "sys_delivery_date", gs.now());
cart.setVariable(item, "sys_comments", 'System generated termination request for expired contractor account.');
var placeOrder = cart.placeOrder();
var request = placeOrder.getValue('sys_id');
Use the 'request' value to do your query.
Hope that helps!
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2017 07:01 AM
Tim,
It seems that this is a common question, there is another post that may assist.
how to set requested for and opened by in a request using the cart API?
However, I resolved this issue by creating an approval within my workflow at the RITM level, and process the approval from there, even tho the request fields are incorrect, I can still control the direction after the request has started.
I don't think this is the correct way, but works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2017 07:13 AM
Thanks Wade.
The other way I had considered would be to use the Service Catalog API (scripted rest api). I am not too familiar with it, though it might be a better alternative than using the Cart API or implementing additional business rules, etc to set those fields correctly.
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2020 08:03 PM
Hi Tim,
Hope you all are safe and healthy ,
I have same requirement but need to generate 4 tasks and as well as 4 different assignment groups,
How can i achieve this could you help me on this please ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2020 07:35 AM
I think you can use the same code as above, and kick off a flow/workflow which will create the tasks for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2020 02:37 AM