- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 05:06 AM
Hi All,
I have a requirement to restrict a date field to be not more than 2years from another date field. Example, If the field Date_A is '25-05-2023' then we should restrict to select only up to '24-05-2025' in Date_B field. Can you please help to achieve this.
TIA,
Surya. P
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 05:25 AM
Hi @Surya_Prakash ,
Please use Catalog UI Policy which needs no/Less coding:
Just adjust the date to be "@ years" for your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 05:25 AM
Hi @Surya_Prakash ,
Please use Catalog UI Policy which needs no/Less coding:
Just adjust the date to be "@ years" for your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 05:43 AM
Hi @Surya_Prakash ,
You can use below on change client script to do the vaildation
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var today_dateStr = formatDate(new Date(),g_user_date_time_format);
var days_from_today = new Date();
//add 730 days to today's date.
days_from_today.setDate(days_from_today.getDate()+730);
var days_from_todayStr = formatDate(days_from_today,g_user_date_time_format);
var todayNum = getDateFromFormat(today_dateStr,g_user_date_time_format);
var daysNum = getDateFromFormat(days_from_todayStr,g_user_date_time_format);
var selected_dateNum = getDateFromFormat(newValue,g_user_date_time_format);
if(selected_dateNum < todayNum || selected_dateNum > daysNum) {
g_form.addErrorMessage('Selected date should be between Today and 2 years from Today');
g_form.clearValue('your field name');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 06:17 AM
Hello @Surya_Prakash ,
Here in the below example, I am adding 2 years in start date field and aborting the action if end date selected is more than startdate+2 years in Business rule.
You can verify this and use this in your scenario.
Please mark as Helpful if my solution is useful.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 06:20 AM
Hi @Community Alums,
Thanks for that, it works fine now.
Thanks,
Surya. P