RITM 'opened by' field not populating when request is triggered through script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 01:19 PM
Hi all,
I have a script include to trigger a catalog request based on some conditions. Everything is working fine(request is triggered, variables are set etc.) but the 'opened by' on the RITM is setting as blank.
Any thoughts on how to set RITM field from a script?
Hard coded solution is also fine, as I can set the sys ID of the user (as it is the same user always)
I tried below 3 scenarios but no luck
1. cart.setValue("opened_by", "SYS_ID OF USER");
2. item.setValue("opened_by", "SYS_ID OF USER");
3. var rc = cart.placeOrder();
rc.opened_by = "SYS_ID OF USER";
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 01:21 PM
Can you post the whole script? Are you using a scheduler to run this script?
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 01:25 PM
Please use use below sample code
var cart = new global.Cart(gs.generateGUID());
var item = cart.addItem('30db7eb84fd95740dc984da28110c7af');
cart.setVariable(item,'requested_for',current.caller);
var rc = cart.placeOrder();
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 01:34 PM
'requested_for' technically isn't a variable on the catalog item, so you can't use that method to set the variable. You can run a query after the cart is submitted and set the opened_by:
var cart = new global.Cart(gs.generateGUID());
var item = cart.addItem('30db7eb84fd95740dc984da28110c7af');
cart.setVariable(item,'requested_for',current.caller);
var rc = cart.placeOrder();
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(rc)) {
ritmGr.setValue('opened_by', current.caller);
ritmGr.setValue('request.requested_for', current.caller);
ritmGr.update();
}
Something to that effect (I have not tested this code). Alternately, you can try using the 'CartJS' library:
There is a 'setRequestedFor()' method available.
Hope that helps!
Cheers,
Tim