Setting the requested_for and opened_by through cart script

Inactive_Us2432
Kilo Contributor

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);

6 REPLIES 6

senthilkannandp
Kilo Expert

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


They are on the REQ & RITM tables but they are not catalog variables.


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


davestreatfield
Kilo Contributor

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.