Setting the requested_for and opened_by through cart script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2016 08:44 AM
This is my code for creating the request, but i am having issues inserting the requested_for and opened_by
any help would be great, everything else works perfect.
Thanks,
var catItem = new GlideRecord("sc_cat_item");
catItem.addQuery("name", "=", "Windows Security Group - Add/Remove Members - Automated");
catItem.addQuery("active", true);
catItem.query();
if(catItem.next())
{
var cart = new Cart();
var item = cart.addItem(catItem.sys_id);
cart.setVariable(item, "requested_for", "fdce3911e904300020939befc5e26736");
//cart.setVariable(item, "opened_by", "fdce3911e904300020939befc5e26736");
cart.setVariable(item, "GroupName", JSON.stringify(groupJSON));
cart.setVariable(item, "GroupType", groupScope);
cart.setVariable(item, "GroupOwnerName", approver);
cart.setVariable(item, "ApproverName", approver);
cart.setVariable(item, "RemoveUserOrGroup", JSON.stringify(userJSONRemoven));
cart.setVariable(item, "RemoveAll", membersRemoveAll);
cart.setVariable(item, "BusinessCase", "Test");
//form has different list collector for Universal/Global groups
if(groupScope == "Universal")
{
cart.setVariable(item, "AddUserOrGroupUniversal", JSON.stringify(userJSONAddn));
}
else
{
cart.setVariable(item, "AddUserOrGroupGlobal", JSON.stringify(userJSONAddn));
}
var rc = cart.placeOrder();
updateRITM(rc.sys_id);
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 05:20 AM
Hi Shay,
Please ensure the "requested_for" and "opened_by" variables are available in the catalog item.
And,
If you want set the requested for as current login user, you can use like below,
cart.setVariable(item, 'requested_for' , gs.getUserID());
Please check the same and let me know any issues.
Thanks,
Senthil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 05:36 AM
They are on the REQ & RITM tables but they are not catalog variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 05:55 AM
Hi Shay,
In that case the requested_for, opened_by value need to be set it in workflow of that catalog item. The Cart method will be useful for set the catalog variable. Not in REQ or RITM.
Thanks,
Senthil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2017 05:28 AM
Hi Shay,
with your line "var rc = cart.placeOrder();" you are creating a Request Item object with variable name rc, so you can put in your data after creation by adding this immediately after:
rc.opened_by = 'fdce3911e904300020939befc5e26736';
rc.requested_for = 'fdce3911e904300020939befc5e26736';
rc.update();
It should filter down to your RITM and TASK too.