- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Team,
I am facing an issue with a Catalog UI Policy in Employee Center.
Requirement:
- I have a Course Cost variable of type Single Line Text (there is no Integer/Decimal variable type available).
- I have a Rich Label variable (retention policy) and a checkbox (retention consent).
- The Rich Label and checkbox should be displayed only when:
- Course Cost >= 10001
- Requested For Location contains Asia
My Catalog UI Policy condition is:
- course_cost >= 10001
- Requested For Location contains Asia
The UI Policy has:
- On Load = Checked
- Reverse if False = Checked
The UI Policy Actions make both the Rich Label and checkbox Visible = True.
I also have:
- An onSubmit Catalog Client Script that validates the Course Cost and prevents submission if the value is not numeric.
- An onChange Catalog Client Script that calculates the retention period based on the Course Cost.
Issue:
If I enter an invalid value such as abc or hrdfbdfdh in the Course Cost field, the Employee Retention Policy (Rich Label) still becomes visible, even though the value is not numeric and the UI Policy condition should not evaluate as >= 10001.
Has anyone experienced this behaviour with Rich Label variables and Catalog UI Policies in Employee Center?
- Is this a known limitation with Rich Label variables?
- Is there a recommended way to control the visibility of a Rich Label based on a numeric value entered in a Single Line Text variable?
Any suggestions would be appreciated. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hey@aparnaravi
This is not specifically a Rich Label limitation. The main issue is that Course Cost is a Single Line Text variable, so using a numeric condition such as course_cost >= 10001 in a Catalog UI Policy is not reliable when the value contains non-numeric characters.
I would not use the UI Policy condition for the numeric comparison. Instead, validate and control the visibility using an onChange Catalog Client Script.
For example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
var cost = (newValue || '').trim();
var location = g_form.getValue('requested_for_location') || '';
var validNumber = /^\d+(\.\d+)?$/.test(cost);
var showRetention = validNumber &&
parseFloat(cost) >= 10001 &&
location.toLowerCase().indexOf('asia') > -1;
g_form.setDisplay('retention_policy', showRetention);
g_form.setDisplay('retention_consent', showRetention);
if (!showRetention)
g_form.setValue('retention_consent', 'false');}
Replace requested_for_location, retention_policy, and retention_consent with the actual variable names.
If Requested For Location is a reference variable, getValue() returns the sys_id rather than the location name. In that case, use getReference() or populate the location into another variable and perform the check against that value.
I would also keep the existing onSubmit validation to prevent non-numeric Course Cost values from being submitted.
Also ensure both fields are hidden initially, either through a UI Policy or by calling setDisplay(false) onLoad.
So the recommended approach is:
Use the UI Policy only for simple visibility requirements.
Use a Catalog Client Script for the numeric comparison because Course Cost is stored as text.
Validate the value with a numeric regex before calling parseFloat().
Explicitly hide the Rich Label and checkbox when the value is invalid.
This should behave consistently in Employee Center and prevents values such as abc or hrdbfdfdh from satisfying the Course Cost condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @aparnaravi ,
1.Update the catalog variable,Under Type specification related list ,make validation regex = number and save record.
2.Now The input accept only numbers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you for the information. I made the suggested changes, and now when I enter characters in the Course Cost field, it correctly identifies the value as invalid (not a number).
However, I still have an issue. I have created a Catalog UI Policy to display the Employee Retention Policy only when the Course Cost is greater than 10000. Despite this, if I enter non-numeric characters (for example, abc), the Employee Retention Policy is still displayed.
Thank you for the information. I made the suggested changes, and now when I enter characters in the Course Cost field, it correctly identifies the value as invalid (not a number).
However, I still have an issue. I have created a Catalog UI Policy to display the Employee Retention Policy only when the Course Cost is greater than 10000. Despite this, if I enter non-numeric characters (for example, abc), the Employee Retention Policy is still displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @aparnaravi,
Use onChange Client Script for your requirement instead of UI Policy. Or add the integer parsing code in the UI Policy script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var cost = parseInt(newValue, 10);
var location = g_form.getDisplayValue('requested_for_location');
var show = !isNaN(cost) &&
cost > 10000 &&
location.indexOf('Asia') > -1;
g_form.setDisplay('retention_policy', show);
g_form.setDisplay('retention_consent', show);
}
You can parse integer from string text and check if your condition matches or not.
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
my thoughts
-> use onChange catalog client script and convert the value to integer and then compare and have your logic
-> use onSubmit script as it is
create new onChnage script as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
var cost = parseInt(newValue, 10);
var location = g_form.getValue('requested_for_location') || '';
var shouldShow = !isNaN(cost) && cost >= 10001 && location.indexOf('Asia') > -1;
g_form.setVisible('retention_policy_label', shouldShow);
g_form.setVisible('retention_consent', shouldShow);
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader