
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-21-2019 07:45 PM
Have you ever been frustrated by the two-step order process having a field called requested_for that you can't set from your catalog item? Sometimes you want the person an item is requested for on your form simply so you can set other options like the appropriate approver, here's how you can do this WITHOUT modifying any portal widgets.
ServiceNow documents an option for the service portal widget that allow you to set a custom Request for user, but somewhat surprisingly, it only allows for a hard coded value (which doesn't make sense to me).
Here's a screenshot from the documentation.
But this gives us the opportunity to dynamically set the options for the widget whenever a particular field changes. As an example...
The code is a little complex as it involves a bit of angular scope magic, but I've commented it so you should be able to follow the logic. If in doubt, write the various scope objects out to the console log so you can see what they contain.
- Your catalog item, record producer or order guide should have a reference field requested_for that looks at the sys_user table
- You'll need to add this as an onchange catalog client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//ServiceNow allows for the requester to be set in the options of the SC Catalog Item widget, but it's a static value
//We'll take advantage of this and transform it into a dynamic value using the angular scope object
//https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-management/task/request-cat-item-portal.html
try{
//First, get the angular scope for the catalog item widget as that has both options and variable values stored in it
//If sc_cat_item isn't there, we're probably within an order guide so we'll grab that scope instead
var catItemScope = this.angular.element('#sc_cat_item').scope();
var orderGuideScope = this.angular.element('div[sn-atf-blacklist="IS_SERVICE_CATALOG"]').scope();
//Find the parameters for this depending on whether it's an order guide or a catalog item
var widgetParameters = catItemScope === undefined ? orderGuideScope : catItemScope.$parent;
//newValue is the sys_id for the requestor selected by our user
widgetParameters.options.requested_for_id = newValue;
//ServiceNow doesn't have an easy way of getting display values beyond using Glide Ajax or a g_form.getReference
//but rather than doing an ajax call, we'll simply grab the name of this user from the scope as it's already there
var displayValue = widgetParameters.data.sc_cat_item._fields.requested_for.displayValue;
//Now we set options display value and we're done
widgetParameters.options.requested_for_display = displayValue;
}catch(e){
//If we run into any problems, we'll print the scope to the console
console.log('%cOh no, an error occured in the client script Update Requested For','color:red');
console.log(e);
console.log(catItemScope);
console.log(orderGuideScope);
}
}
I've adapted this script so it works with catalog items and order guides (but the reference field needs to be on the order guide not buried away in one of the various items in the guide)
Also, I've attached the catalog script to this article.
Have fun
- 8,075 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Wonderful... thank you!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Peter,
Is this not work for Order Guide? It is working absolutly fine for catalog items but its not working for order guide. Do we need to modify the script for Order guide?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, the order guide uses a different widget called widget-sc-order-guide-v2 but if you make the same change there it will work
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hy Peter,
I also tried to implement this in the Order Guide but unfortunately I didn't succeed. I made changes but this had no effect on "Requested for" in the pop-up when ordering ?? I ask for help to solve the problem !!!
!! Please give me instruction !!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I've modified the script so it works with either a catalog item or order guide. Hope that helps

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I've modified the script so it works with either a catalog item or order guide. Hope that helps
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for your help !!! Everything worked wonderfully !!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Solutions looks good but not best.
It is setting the Requested For from the catalog item to the confirmation page.
But what If I am changing Requested For, on the confirmation page, it should be reflected in the catalog item (which is not happening OOTB or with your code).
Basically, when I set Requested For on the confirmation page, it should be updated on the catalog item as well. But vice-versa is happening now with your code.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Make sure you're following the instructions above carefully as it should work fine. Also, you'll notice there are console.log statements that occur if an error is triggered. You could add additional console.log statements to assure yourself that the script is running

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In that case, the best approach is to handle this in a business rule. The reason for this is your catalog item is being processed once the person hits 'confirm' on the confirmation page. So I'd add a BEFORE business rule that checks to see if the requested_for value on the sc_request table differs from the variable you're using to capture who the request is for and updates that if they are different. Have fun
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Peter,
Thanks for the code. Will it work in scenarios like below.
For example, a manager is requesting on behalf of his two employees say A and B. For A he has given the A name in variable and added to cart and same for B. Now we have two catalog items in the cart and now manager needs to checkout it. So what name will it pickup among the two?
Regards,
Rakesh
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mahesh,
It is not working for me on catalog item. I have created catalog on change client script on rquested_for variable but it is not working. Can you please tell me the steps what I need to follow to make this successful.
Thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Wonderful solution!
Thank you

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If you have a manager ordering for multiple people, you need to either have them place multiple orders for each person (this would be best practice) or include a multi-row variable set allowing them to enter multiple people then at the back end your fulfillment team would have to manage the request appropriately.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
is there a way to make this update the Full client confirmation also??
servicecatalog_checkout_one_v2

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How can I get this solution to work from the cart. When I add to cart and checkout from the cart screen. The requested for is not reflecting the requested for from the variable
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This might be the right thread to ask this on. In our Service Portal, when a user makes a Request for a different user it creates a REQ######## form that gets pushed to my team (Requested by vs Requested for). But in that form, the "Requested For" field is incorrect. It fills it out with the user who created the request, not the user who it is being requested for (which is what we want)
Thanks in advance for any assistance. New to SN, so maybe the above is what I'm looking for as a fix.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @petercawdron ,
Where exactly I should replace the widget-sc-order-guide-v2 in the code for order guide
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I created a requested for variable of type reference and wrote the code for order guide, it worked fine when I included the widget-sc-order-guide-v2 in my script, but later on changing the user in the custom variable I created, i am not able to get the same username in the confirmation popup. I am getting the same name which I have chosen in the first. Below is the script code, Please help me with the issue
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//ServiceNow allows for the requester to be set in the options of the SC Catalog Item widget, but it's a static value
//We'll take advantage of this and transform it into a dynamic value using the angular scope object
//https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...
try{
//First, get the angular scope for the catalog item widget as that has both options and variable values stored in it
//If sc_cat_item isn't there, we're probably within an order guide so we'll grab that scope instead
//widget-sc-order-guide-v2
// #sc_cat_item
var catItemScope = this.angular.element('#sc_cat_item').scope();
//var orderGuideScope = this.angular.element('div[sn-atf-blacklist="IS_SERVICE_CATALOG"]').scope();
var orderGuideScope = this.angular.element('widget-sc-order-guide-v2').scope();
//Find the parameters for this depending on whether it's an order guide or a catalog item
var widgetParameters = catItemScope === undefined ? orderGuideScope : catItemScope.$parent;
//newValue is the sys_id for the requestor selected by our user
widgetParameters.options.requested_for_id = newValue;
//ServiceNow doesn't have an easy way of getting display values beyond using Glide Ajax or a g_form.getReference
//but rather than doing an ajax call, we'll simply grab the name of this user from the scope as it's already there
var displayValue = widgetParameters.data.widget-sc-order-guide-v2._fields.requested_for.displayValue;
//Now we set options display value and we're done
widgetParameters.options.requested_for_display = displayValue;
}catch(e){
//If we run into any problems, we'll print the scope to the console
console.log('%cOh no, an error occured in the client script Update Requested For','color:red');
console.log(e);
console.log(catItemScope);
console.log(orderGuideScope);
}
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This worked perfectly, however now I have the problem of it leaving the approvers related to the person who created it. How do we address checking/changing the approving manager?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @petercawdron ,
Thanks for sharing your solution! It’s quite similar to what I’m working on. However, my requirement is to update the request field on the checkout widget before the 'Order Now' button is clicked. I attempted to change the widget ID, but the update only takes effect after clicking the button. Do you have any suggestions on how I can trigger the field update earlier in the process, without waiting for the submission?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
var catItemScope = this.angular.element('#sc_cat_checkout').scope();
var orderGuideScope = this.angular.element('div[sn-atf-blacklist="IS_SERVICE_CATALOG"]').scope();
var widgetParameters = catItemScope === undefined ? orderGuideScope : catItemScope.$parent;
widgetParameters.options.requested_for_id = newValue;
var displayValue = widgetParameters.data.sc_cat_item._fields.customer.displayValue;
widgetParameters.options.requested_for_display = displayValue;
} catch (e) {
console.log('%cOh no, an error occured in the client script Update Requested For', 'color:red');
console.log(e);
console.log(catItemScope);
console.log(orderGuideScope);
}
}