date variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:00 AM
Hi All,
I have a date variable 'xyz' which value is getting auto populated based on other 2 variable's values but still not read only. When the value of the date variable 'xyz' is not empty then I need to restrict the user to select any date which is greater than the current value of that date variable xyz that means user can select any date till the date which is already getting auto populating but not greater than that.
I want to do it using on change client script.
Can you please help me out.
Thanks in advance.
Regards,
Abhisek Chattaraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 07:10 AM
Hi @MukkamalaM
Thanks for your reply.
I am not allowed to create another hidden variable.
Thanks&Regards,
Abhisek Chattaraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 07:44 AM
Please use the following script and make adjustments as necessary!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 06:51 AM
Hello @abhisek
Try this onChange client script to meet your requirement:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (oldValue && newValue) {
// Convert the old and new values to Date objects
var oldDate = new Date(oldValue);
var newDate = new Date(newValue);
// Compare the new date with the old date
if (newDate > oldDate) {
// Show field error message if the new date is greater than the old date
g_form.showErrorBox('date','date cannot be greater than autopopulated value');
//g_form.setValue('date', oldValue); // Optionally, reset the field to the old value (auto-populated)
} else {
// Hide the error message if the new date is valid
g_form.hideErrorBox('date');
}
}
}
Result:
Here the auto-populated value is '2025-01-05'
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 07:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 07:22 AM
Hello @abhisek
Can you please share your script?
Additionally update the variable name for showErrorBox and HideErrorBox. In the script I have mentioned it as 'date'.
Thank You
Juhi Poddar