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 would suggest you change your script to the following then.


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;


}



Now the concept you are trying to apply will only work if there is only one request item linked to one request or you have multiple request items with same Requested for linked to one request.


As soon as you have multiple request items with each RITM having different requested for, your concept will break because a request is always raised for a single user. The user can opt to select multiple services in a single request thus creating multiple RITM's. If there is a service, where a user can raise request for other users, then the Request should be opened for the user raising the request but the RITM's can be opened for the users for whom that particular service is raised.



Hope this will help.



Regards,


Ishant


u_requested_for is on the requested item table, not Request, does that matter? There is no current.u_requested_for on the Request table.


Is your workflow not attached to Requested Item table? if not, then it should be attached to RITM table because RITM will be the record driving your workflow for the service requested by user. Once it's attached to RITM table, current.u_requested_for will point to u_requested_for of RITM table.


Ahmed15
Tera Contributor

Create a client script for the request.




Example:



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading   || newValue == '') {


  return;


  }



  var sc = new GlideRecord('sc_cart');


  sc.addQuery('user', g_user.userID);


  sc.query();


  while (sc.next()) {


  sc.requested_for = newValue;


  sc.update();


  }


}


chintu2
Kilo Contributor

can you look once : Call to Request