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

Not applicable

Oh you have no idea how hard I am working to find the answer to this very question...

I have record producers which happily populate the value from a variable which has the field name, i.e. requested_for, but for a catalog Item which is not a record producer, the same variable just sits there as a variable. Because these requests are done via an order guide or request, and not the table's form view, I gather there's a whole lot of code running in the background to generate the requests and items. I can't find anywhere to script it.

I hope someone very clever and important helps us out!


benn32
Kilo Contributor

I think I've figured it out.
When you open up the service catalog for the first time, it creates a record (that it will update each time you visit the service catalog) in the sc_cart table. This record consists of your user ID, and the 'requested_for' id. So, when you change the 'requested for' id in the service catalog, it's pushing the new value off to that record. When you submit your item, it's calling that record to see who to make the "request for."
So, I have my 'request for' information inside the item. I wrote a client script on load that pulls the 'request for' from MY sc_cart record.

function onLoad() {
var userid = g_user.userName;
var cart = new GlideRecord('sc_cart');
cart.addQuery('user.user_name', userid);
cart.query();
if (cart.next()) {
var reqfor = cart.requested_for;
g_form.setValue('emp_id_pager', reqfor);
}
}

Now... What if someone realizes that the 'request for' is incorrect once they're in an item? I created a client script to push the new value off to MY sc_cart record when the value is changed (from inside the item). Again, once the item is ordered, it'll read this new value.

function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
var userid = g_user.userName;
var newid = g_form.getValue('emp_id_pager');
var cart = new GlideRecord('sc_cart');
cart.addQuery('user.user_name', userid);
cart.query();
if (cart.next()) {
cart.requested_for = newid;
cart.update();
}
}
}


Not applicable

Great - thanks.

For a record producer the requested_for is set at request level on submit, and it was bugging me that I couldn't change the requested_for with a variable on a catalog item which was not a record producer. It just kept defaulting to the logged in user.

I found that the "checkout" option (2-step catalog ordering) allows you to specify a different requested_for which overrides the sc_request level, which is what I need, but I didn't necessarily want to force all requests to go via the checkout - I'm using "order now".

I'll see how I go now that I have your valuable information. It looks as if I just need to push the value of my item 'employee' variable to the cart.requested_for

Thanks,

Jenny.


Not applicable

Genius - it works !
I'm using 2-step order guides too, but I've found that if you turn ON the 2-step catalog ordering, the 2-step on the order guide reverses the 2 step of the catalog level property and tuns it OFF!

I've added the catalog client scripts to a variable set which I use on all Access Requests because we only want managers to request - then I have used a reference qualifier so they are only able to see their own direct reports.
That way I don't need to bother them with an approval request as well.

Jenny