
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-16-2019 12:53 AM
Hi there,
With the release of Madrid, a nice new feature was introduced: "Variable Validation Regex". In short, you can add a validation on (single-line text) variables through selecting a record from a reference field. The reference field displaying regex choices. This way, you can easily add validations, re-use validations, you won't have to write Catalog Client Scripts over and over anymore, etc.. You can read more about this in one of my previous articles: Service Portal Catalog Items: Regex Field Validation [Madrid].
Issue
Unfortunately though, this new feature does not work flawlessly. There's a nasty bug (and still on New York)… When applying the Regex Variable Validation on a mandatory variable, and the validation triggered to display the error message, the user gets stuck when trying to submit the Catalog Item. For non-mandatory variables, this is not an issue.
ServiceNow has this listed as a PRB, PRB1355430.
"If there's a mandatory variable validated by a regex, it's still possible to submit the catalog item, however, it'll get stuck on submit.
If the variable isn't mandatory, it'll be validated correctly and the item can't be submitted"
There is no targeted fix at this moment.
Workaround
Because this is a nice feature, saves creating a Catalog Client Script over and over, a no/low-code admin can use this as well, we wanted to use this feature a.s.a.p.. During our investigation on this issue, we came up with a workaround. It's not a 100% workaround, though very workable. In short: if the mandatory variable is filled, change the mandatory attribute to false. This prevents the Catalog Item from getting stuck if the Regex Variable Validation wasn't correct and the user tried to submit the Catalog Item.
So how to make a mandatory variable not mandatory? There are multiple situations.
- A variable which is made mandatory on the variable itself, thru the mandatory flag
- A variable which is conditionally made mandatory thru Catalog UI Policies and Catalog UI Policy Actions
- A variable which is conditionally made mandatory thru Catalog Client Scripts
Easiest are the variables which have the mandatory attribute flag checked on the variable itself, and no conditional mandatory in place. On these you could simply set up one Catalog UI Policy and Catalog UI Policy Action (no-code) or one Catalog Client Script (low-code). Don't forget to uncheck the mandatory attribute flag on the variable itself!
Catalog UI Policy and Catalog UI Policy Action
Catalog Client Script
Tougher are the conditional mandatory variables. Especially when there multi-level deep. Though, the basic thought will be the same. If the variable is filled, change the mandatory attribute flag to false. How to apply this is just a little different. Create two Catalog UI Policies with each one Catalog UI Policy Action. The first Catalog UI Policy Action is for if the variable is empty (and the Catalog UI Policy Action contains mandatory=true), and create a second Catalog UI Policy Action for if the variable is not empty. Two Catalog UI Policy Actions because… you have to uncheck the "Reverse if false" flag!
The regular Catalog UI Policy you would already have for conditional show/hide the variable:
Note: The "Clear the variable value" is used on the Catalog UI Policy Action. Read more about this in one of my previous articles: Clear the field value / Clear the variable value
Result
The result on the Service Portal with the conditional visible mandatory variable:
Variable being mandatory if left empty:
Variable made not mandatory if not empty, the actual workaround 🙂
---
And that's it actually! Not a perfect / 100% workaround, though workable. And with this, the no-code Variable Validation Regex could be applied. Also, ones this issue is fixed by ServiceNow, you could easily revert the workarounds put in place. Too easily identify which Catalog UI Policies or Catalog Client Scripts have been set up for this workaround, for example mention the PRB in the description of the Catalog UI Policy / Catalog Client Script.
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful. Interested in more articles, blogs, videos, and Share Projects on Service Catalog I published? - Service Catalog |
Kind regards,
Mark
---
- 5,126 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great fix Mark, we can use this workarround until we get permenant soution from ServiceNow!
To find detailed steps on how to implement variable validation Regex check the below Article.
Variable Validation Regex on Madrid - Steps to Implement
-satheesh
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very helpful to know it is a known error, I wasted hours thinking that it was my customer's instance. I had to apply your workaround as well. Thank you for your help
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks! This thread helped me figure out a small nightmare...
I was developing a new RP and added a var set (mrv) for my users. I pre-populate the mrv based on other input. I used a Validation Regex on 2 out of 3 vars. It was working great fine and then I couldn't submit if the submitter did nothing and just clicked submit... Thank goodness I found this fairly quickly. I didn't have any mandatory var but realized that it must have to do with the validation Regex being unable to execute
I then realized that the regex didn't cover the double zero scenario I recently added. 0-100 but not '00' which was desired to represent 0%. Hope this helps someone else.
I took a look at my scenario in Orlando it looks like it will at least kick out an error message to the user. You get a validation message for each instance of violation (unfortunately all in one error message)... which is a little more comforting and may be useful to others.
Marc