- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 04:13 PM
Hi All,
We are running Helsinki patch 5 and have started to look at implementing the shopping cart in the Service Portal. The problem we are having is trying to make fields mandatory. See screenshot below showing the field we would like to make mandatory:
We have client script code that is set to run for both mobile and desktop set for the UI type. This works in the Service Catalog but not in the Service Portal when attempting a checkout without a Business Justification set. I am assuming I need to set this in the client script of the widget in question, just not sure where to start with the code for this.
Does anyone have some links to good resources to help with developing widgets?
Thanks
James
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 08:50 AM
James,
I'd first like to caution you about leveraging the Helsinki Patch 5 shopping cart widgets. We're not sure why they were included since the Shopping Cart and Bundles in Service Portal are most likely not being released until Istanbul.
That said, it appears from your screenshot that you are trying to make the relabeld Special Instructions field, "Business Justification", field mandatory in the "SC Shopping Cart" widget.
The HTML for that field is in the sp_ng_template called "large_shopping_cart.html" record:
Since you've already taken ownership of the "large_shopping_cart.html" template record you could add in a "placeholder" value that also draws attention to the mandatory nature of this field.
You could add the following to the "Client Script" on the "SC Shopping Cart" widget
Between Lines 13-14 add the following:
if (c.additionalDetails == '') {
- spUtil.addErrorMessage('Business Justification is required before Checkout. Thank you!');
- return;
}
And you could add some CSS to the "SC Shopping Cart" widget to draw attention to the mandatory "Business Justification":
I'm adding minimal CSS here but you could go further...
.special-instructions-details label {
color: tomato;
}
Results:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 06:24 AM
Hi James,
If you're using a catalog client script to make that field mandatory in your catalog you should also be able to do that in the service portal. I'm wondering if somewhere in your client script you're using something unsupported in SP so the script isn't working. Could you post your client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 07:03 AM
Either one of these should work.
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setMandatory('your_variable_goes_here' , true);
}
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.setMandatory('your_variable_goes_here' , true);
}
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 08:50 AM
James,
I'd first like to caution you about leveraging the Helsinki Patch 5 shopping cart widgets. We're not sure why they were included since the Shopping Cart and Bundles in Service Portal are most likely not being released until Istanbul.
That said, it appears from your screenshot that you are trying to make the relabeld Special Instructions field, "Business Justification", field mandatory in the "SC Shopping Cart" widget.
The HTML for that field is in the sp_ng_template called "large_shopping_cart.html" record:
Since you've already taken ownership of the "large_shopping_cart.html" template record you could add in a "placeholder" value that also draws attention to the mandatory nature of this field.
You could add the following to the "Client Script" on the "SC Shopping Cart" widget
Between Lines 13-14 add the following:
if (c.additionalDetails == '') {
- spUtil.addErrorMessage('Business Justification is required before Checkout. Thank you!');
- return;
}
And you could add some CSS to the "SC Shopping Cart" widget to draw attention to the mandatory "Business Justification":
I'm adding minimal CSS here but you could go further...
.special-instructions-details label {
color: tomato;
}
Results:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 02:36 AM
Hi Jeremy,
When I am trying to add the same code for reference field it is not working. My use case is that I have created three new fields like approving manager, cost center, department.
Approving manager will be autopopulated based on the user, if some user doesn't have manager, then in that case the field will be empty and whenever the values changes to empty, we have to show this error message.. Can you help me