- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 09:55 PM
Hi ServiceNow Community,
I'm trying to achieve the following behaviour in my catalog item:
I have a variable required_by_date, and I want it to be displayed only if the Yes/No variable inside my variable set ("Required Accessories") is selected as YES. Additionally, when it is displayed, it should also be mandatory.
I couldn't find a direct way to achieve this since UI Policies don’t seem to work in this case. I suspect this is because the data is inside a variable set.
Has anyone faced a similar issue? I'd really appreciate a different approach or a workaround to make this work.
I've attached some images for better reference.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 11:15 PM
I created two catalog client scripts to achieve the desired behaviour. It’s a simple approach, but it works for what I need.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'Yes') {
if (this) {
this.cat_g_form.setVisible('required_by_date', true);
this.cat_g_form.setMandatory('required_by_date', true);
}
}
if (newValue == 'No') {
if (this) {
this.cat_g_form.setVisible('required_by_date', false);
this.cat_g_form.setMandatory('required_by_date', false);
}
}
}
Catalog Client Script (onLoad):
function onLoad() {
this.cat_g_form = g_form;
}
By using this.cat_g_form = g_form in the onLoad script, I ensured that the g_form object is accessible within the Variable Set script. This is necessary because scripts inside a Multi-Row Variable Set don’t have direct access to g_form by default. Assigning it to this.cat_g_form allows the onChange script to properly reference and manipulate the catalog item fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 10:19 PM
Hi @JGuerrero0323 ,
Create a UI policy on the catalog item that provides access to both the variable set fields and the catalog item fields. This approach will allow you to achieve the desired scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 11:00 PM
Hi Moin,
That approach is not possible because a UI Policy created at the catalog item level cannot directly control fields within a Variable Set. UI Policies only apply to fields at the same level they are defined, so they cannot enforce changes on fields inside a Multi-Row Variable Set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 10:27 PM
Hi @JGuerrero0323 ,
I think you have a similar requirement as mentioned in this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 10:31 PM - edited ‎03-03-2025 10:34 PM
Create the Catalog Client Script:
- Go to your catalog item.
- In the Catalog Item record, scroll down to the Catalog Client Scripts related list and click on New.
- Select Type: onChange.
- Choose the Variable for the Yes/No question (e.g., "Required Accessories").
Write the Script: Here's a sample script that should do the trick:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}// Get the "Required by Date" variable
var requiredByDate = g_form.getControl('required_by_date');// Check if the "Required Accessories" Yes/No variable is YES
if (newValue == 'true') { // 'true' for Yes
g_form.setVisible('required_by_date', true); // Show the date
g_form.setMandatory('required_by_date', true); // Make it mandatory
} else {
g_form.setVisible('required_by_date', false); // Hide the date
g_form.setMandatory('required_by_date', false); // Make it optional
}
}
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Sachi Pai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 10:38 PM
you have MRVS and based on MRVS variable value outside variable needs to be shown/hidden.
So it's not straight forward.
But what if user adds multiple rows 1 with yes and other with no?
what will happen in that case?
I suggest to add that Date variable within MRVS so that it makes more meaning to the users and they can specify for each row when they require.
Once this is done you can use catalog UI policy which applies on MRVS and on that Yes/No variable and show/hide the other date variable and make it mandatory
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader