Add requested for to service catalog

will_smith
Mega Guru

My client is wanting to add the Requested For (requested_for) field to some catalog items. I know how to add the reference field to the user record and populate the default value with the current user. What I am having some trouble with is then getting that field to show up in the cart's order status page as well as reflecting on the REQ/RITM - the field is already added to the form, it's just not updating with the catalog item information. I am definitely going to need some help with this, as I've not edited the cart before.

Below are the steps I have taken so far...

  1. I've added Requested For (requested_for) to my test catalog item form.
  2. Add requested for to the order status page. I was able to complete that with this cart widget macro: Create macros for cart layout example. Order Status_ REQ0016234 _ WESCODEV - ServiceNOW_06-03.png
  3. I've looked at this community article on populating the Request with the catalog item variable, but have yet to implement it successfully. How do I add a requested for field on a request form in a service catalog?

To sum up, what I'm needing help with is taking the requested for variable from the catalog item and pushing it to the cart order status page, and the request/requested item(s) that gets created.


Thank you for your help!

1 ACCEPTED SOLUTION

HugoFirst
Kilo Sage

That is an excellent question William!         I suppose you are referring to a situation where each requested item may have a different person in the requested_for field.   If this is the case, then the request record by itself is not adequate to reflect that situation, as it's "requested_for" field can only handle a single value.



Here's my ideas for this situation:


1. On your catalog item, add a field for "Requested For".


2. On the requested_item form, add the "Variable Editor".   All variables on the catalog item will now display on your requested item record.



find_real_file.png



Give you something like this on your requested item record:


find_real_file.png


View solution in original post

18 REPLIES 18

I thought of this Chintu, but the issue i ran into is what if there are multiple requested items and they all have a different requested for?


will_smith
Mega Guru

Here is an example, with screenshots, and code for this one catalog item.



var userID = current.variables.requested_for;


var loggedInUser = gs.getUserID();




if (userID){


  var request = new GlideRecord('sc_request');


  request.get(current.request);


  request.requested_for = userID;


  request.update();




  var requestItem = new GlideRecord('sc_req_item');


  requestItem.get(current.request_item);


  requestItem.u_requested_for = userID;


  requestItem.update();


}



I have a specific catalog copying the requested for field to the request_requested_for. Yay!


find_real_file.png



But it's not copying the same information to the Requested Item sc_req_item.u_requested_for.


find_real_file.png


Try below script:




var userID = current.variables.requested_for;


var loggedInUser = gs.getUserID();



if (userID){


  var request = new GlideRecord('sc_request');


  request.get(current.request);


  request.requested_for = userID;


  request.update();



    current.u_requested_for = userID;


  current.update();


}





Thanks,


Mihir


Hi William,



Are you using this script in a business rule on RITM? Can you share more information on how actually you are running this script and when to set the values for requested_for.



Regards,


Ishant


Hi Ishant, this is for item# 3 in my original post (OP).



I am running this from a workflow attached to the catalog item, in a run script right after Begin called "Add requested for to the REQ/RITM"



chrome_2016-06-03_13-38-00.png