I AM unable to set the future date is only one day in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:54 AM
I have one date field (Accept date) in that we will need to select only one future date (like, today is 20 when im doing this i can able to select only 20 or 21) if i select after this date, 22,23, like this alert will trigger for that i write a onchange client script.
could you please help me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 04:01 AM
Hi @Prem96
Name: Give your client script a meaningful name, e.g., “Validate Accept Date”.
- Table: Choose the table where your “Accept date” field is located.
- UI Type: Make sure it’s set to “All” or “Desktop” depending on where you want the script to run.
- Type: Choose “onChange”.
- Field name: Select the field you want to apply the script to, which in your case is the “Accept date” field.
var selectedDate = new Date(newValue);
var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
// Reset hours, minutes, seconds for accurate comparison
today.setHours(0,0,0, 0);
tomorrow.setHours(0, 0, 0, 0);
selectedDate.setHours(0, 0, 0, 0);
// Check if selected date is beyond tomorrow
if (selectedDate > tomorrow) {
alert("Please select today’s or tomorrow’s date.");
// Optionally, clear the field or set it to a default value
g_form.setValue('your_field_name', ''); // Replace ‘your_field_name’ with the actual field name
// Or set to today’s date
//g_form.setValue('your_field_name', g_form.getValue('sys_date')); // Assuming ‘sys_date’ holds today’s date in the correct format
}
}
Remember to replace 'your_field_name' with the actual name of your “Accept date” field, ensuring the field name matches exactly.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma