- 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 11:06 PM
Hi Ankur.
If the required_by_date variable is added inside the MRVS as you propose, each row will have its own date selection. However, the goal is to have a single required_by_date for all items, not separate dates for each row.
Since the requirement is to control the visibility of required_by_date based on at least one "Yes" in the MRVS, keeping it outside ensures consistency and avoids users selecting different dates for different rows
- 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.