- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 04:36 AM
Hi,
The requirement was to create a field on a catalog item where a user can select up to 7 dates for a planned outage.
I made a multi row variable set (MRVS) to fulfill this requirement and added the start and end date/time variables to the MRVS. So far this is working well.
However, the requirement is that the user should not be able to add more than 7 dates and I also need something to check if there is any overlap between the selected dates/times. How can I achieve this?
Is this something that can be done via a catalog client script? and if so how?
is there a better solution than a MRVS for the requirement to start with?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 04:46 AM - edited 05-02-2025 05:16 AM
if you want multiple rows for user to enter then you should use MRVS, if not then single row variable set and have 2 variables directly.
To allow only 7 rows you can max_rows=7 in the MRVS variable set
It all depends on your customer requirement
Now coming to your validation, you can use onSubmit catalog client script which applies to MRVS and then check if it's more than 7 days of Start date
Note: Use this if both are date/time type
function onSubmit() {
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
var minutes = 10080; // 7 days is 10080 minutes
var startDt = new Date(getDateFromFormat(start, g_user_date_time_format)).getTime() + minutes * 60000; // add minutes to date and then compare
var endDt = new Date(getDateFromFormat(end, g_user_date_time_format)).getTime();
if (endDt < startDt) {
alert('End date should be 7 days more than Start Date');
return false;
}
}
Note: Use this if it's date type
function onSubmit() {
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
var minutes = 10080; // 7 days is 10080 minutes
var startDt = new Date(getDateFromFormat(start, g_user_date_format)).getTime() + minutes * 60000; // add minutes to date and then compare
var endDt = new Date(getDateFromFormat(end, g_user_date_format)).getTime();
if (endDt < startDt) {
alert('End date should be 7 days more than Start Date');
return false;
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 04:46 AM - edited 05-02-2025 05:16 AM
if you want multiple rows for user to enter then you should use MRVS, if not then single row variable set and have 2 variables directly.
To allow only 7 rows you can max_rows=7 in the MRVS variable set
It all depends on your customer requirement
Now coming to your validation, you can use onSubmit catalog client script which applies to MRVS and then check if it's more than 7 days of Start date
Note: Use this if both are date/time type
function onSubmit() {
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
var minutes = 10080; // 7 days is 10080 minutes
var startDt = new Date(getDateFromFormat(start, g_user_date_time_format)).getTime() + minutes * 60000; // add minutes to date and then compare
var endDt = new Date(getDateFromFormat(end, g_user_date_time_format)).getTime();
if (endDt < startDt) {
alert('End date should be 7 days more than Start Date');
return false;
}
}
Note: Use this if it's date type
function onSubmit() {
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
var minutes = 10080; // 7 days is 10080 minutes
var startDt = new Date(getDateFromFormat(start, g_user_date_format)).getTime() + minutes * 60000; // add minutes to date and then compare
var endDt = new Date(getDateFromFormat(end, g_user_date_format)).getTime();
if (endDt < startDt) {
alert('End date should be 7 days more than Start Date');
return false;
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:00 AM
Hi @Ankur Bawiskar thanks so much for your help, that is exactly what I needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:05 AM
Glad to help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 04:57 AM
Hi @snow_beginner , for user not be able to add more than 7 dates -
- Inside the Multi-Row Variable Set, there is a field called "Variable Set attributes" (set_attributes). Set its value to max_rows=7.
- Ensure there are no spaces between the equal sign and the number.
If the field "Variable Set attributes" not available in the form, you can bring it to the form by editing the form layout.
For validating the overlapping, are you looking for same duplicate entries or the time overlaps?