- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:12 AM
Hi Community,
How to make start and end date auto populate when you select the year.
Rules :The year of applicability will automatically fill the following fields :
- start date = January 1st of the selected year
- end date = December 31st of the selected year
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:50 AM
Hi @Nani16 Try this. I have not tested
Create onChange client script on Year field and add below code in Client Script
(function executeRule(current, previous /*null when async*/) {
// Get the year from the Year field
var year = g_form.getValue('year');
// Check if the year is a valid number
if (!isNaN(year) && year > 0) {
// Format the start and end dates
var startDate = year + '-01-01';
var endDate = year + '-12-31';
// Set the Start Date and End Date fields
g_form.setValue('start_date', startDate);
g_form.setValue('end_date', endDate);
} else {
// Clear the date fields if the year is invalid
g_form.clearValue('start_date');
g_form.clearValue('end_date');
}
})(current, previous);
Regards,
Sid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:50 AM
Hi @Nani16 Try this. I have not tested
Create onChange client script on Year field and add below code in Client Script
(function executeRule(current, previous /*null when async*/) {
// Get the year from the Year field
var year = g_form.getValue('year');
// Check if the year is a valid number
if (!isNaN(year) && year > 0) {
// Format the start and end dates
var startDate = year + '-01-01';
var endDate = year + '-12-31';
// Set the Start Date and End Date fields
g_form.setValue('start_date', startDate);
g_form.setValue('end_date', endDate);
} else {
// Clear the date fields if the year is invalid
g_form.clearValue('start_date');
g_form.clearValue('end_date');
}
})(current, previous);
Regards,
Sid