Referencing "Request For" While Ordering a Catalog Item

benn32
Kilo Contributor

Does anyone know of a way to grab the 'Request For' value (from the main catalog page) from within a catalog item?
We fear that some of our users will over-look the "Request For" field, which should be defaulted to their User ID. So, they'll click on an item and fill out the 'request for' information (variables) of someone other than themselves, but in actuality, the request will still say it's requested for the person making the request. It would be nice if on load of the item, we could pass the 'request for' value from the main catalog page to the item, and auto-populate some of the user's info. If the 'request for' is changed from within the item, ideally we'd like to pass that value off to the request.
Has anyone done this? If so, we'd really appreciate some guidance!
Thanks.

18 REPLIES 18

sylvain_hauser
Tera Contributor

thanks benn32, it works super great!!!!


First Question
Has any of you tried to request for multiple users?
instead of the default field, it uses a glide_list
is this possible?

Second Question,
I have other field requirements like location, business reason that should be put in the request and not in the item, is this possible?

thanks


1st: I know that there is a copy option on the order summary page that can copy that same request for multiple people. We turned it off since we never really have the same request for multiple people and users also thought that it mean to CC them or copy someone else in an email.

2nd: Couldn't you just not display the "location" or whatever field in the form layout in the item or task layouts so that it only appears on the request form layout?


SteveS
Kilo Expert

We actually don't want the "Requested For" to default to the user id that is logged in since we are not using self service and IT employees are filling it out. I would rather have this field show nothing but be a mandatory field that forces you to fill out who ever the request is actually for. Has anyone done anything like that?


benn23
ServiceNow Employee
ServiceNow Employee

Check out the sc_cart table. This is where the 'request for' info is stored. Each user has their own record in this table and in their record there's a reference to the user they're requesting the item for.
You can create a 'request for' variable in your item and when it's valued you can call a catalog client script that passes this value off to the 'requested for' field in the sc_cart table for your record (user = me).
ex:
an onChange (of the request_for variable) cat client script.
if(!isLoading){
var userid = g_user.userName;
var newid = g_form.getValue('request_for');
var cart = new GlideRecord('sc_cart');
cart.addQuery('user.user_name', userid);
cart.query();
if (cart.next()) {
cart.requested_for = newid;
cart.update();
}
}
}