Business Rule Ordering a request catalog item

tysonwenger
Mega Expert

Hi,

I am trying to generate a request/task using a business rule based on predefined values from another form.     I am having issues setting the "requested_for" value.     Everything seems to work fine, it creates the request, request item, and task.   But the only field that is not properly being set is the "requested for" field.   For some reason it always sets it to the person executing the script, when it should be setting it to "current.u_affected_user".   I even tried setting the cart.requested_for value, but it still doesn't work.  

Also, in the workflow for this catalog item there I do set the requested_for variable based on the variables in the form so it should take that value...

var cartId = GlideGuid.generate(null);

    var cart = new Cart(cartId);

    var item = cart.addItem(workOrderSysID);

    cart.requested_for = current.u_affected_user;

    cart.setVariable(item, 'short_description', short_desc);

    var full_description = 'This IT Internal Request was automatically created from Call Record ' + current.number;

    cart.setVariable(item, 'description', full_description);

    cart.setVariable(item, 'assignment_group', current.u_assignment_group);

    cart.setVariable(item, 'requested_for', current.u_affected_user);

    var rc = cart.placeOrder();

    rc.u_call = current.sys_id;   //add a reference to the initial call into sc_request

    rc.update();

Any help would be much appreciated.

Thanks

1 ACCEPTED SOLUTION

Thanks Pradeep, I actually ended up using this code instead:



var rc = cart.placeOrder();


  rc.u_call = current.sys_id;   //add a reference to the initial call into sc_request


  rc.requested_for = current.u_affected_user;


  rc.short_description = short_desc;


  rc.update();



Thanks!


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Tyson,



Can you please refer my solution here and check if that resolves your issue.


how to set requested for and opened by in a request using the cart API?


Thanks Pradeep, I actually ended up using this code instead:



var rc = cart.placeOrder();


  rc.u_call = current.sys_id;   //add a reference to the initial call into sc_request


  rc.requested_for = current.u_affected_user;


  rc.short_description = short_desc;


  rc.update();



Thanks!


Thanks Tyson for the update.


Glad you got it figured out