- 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-22-2017 07:38 AM

- 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-25-2017 06:00 AM
Tim,
This worked as you suggested, however, one issue remains... the request is generated directly before the update to the requested for, so the approval from the workflow is still set to the manager of the ID that generated the RITM. In this case, I am using the System Admin to create the request, so there is no approver, even thought the requested for is now set to the new value.
Kinda the chicken or the egg thing going on here, any thoughts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 06:38 AM
Wade,
I actually am facing a similar issue in another business rule I created to trigger a notification if a certain user submits a request. Even though the 'requested_for' is set in the workflow (after the REQ is created), it will not trigger the BR. Same chicken/egg scenario.
I haven't figured out a solution yet. One thing I am curious of is in the platform UI, and CMS, at the cart checkout screen, there is a 'requested_for' option, which appears to set that field on the REQ during submission. So, I am sure there is a way to do this, I just haven't figured it out yet
If you do, please post your findings; I will do the same!
Cheers,
Tim