Getting Invalid date in On change CS. Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 07:59 AM
Hi all,
I have start date (u_start_date) and End date (u_end_date) on a catalog item.
I have created an On change Client script on Start date field. I want to show an error message if the user selects today's date or old date, but in the alert message it is showing Invalid date.
Can you please help me here also, I want to write another On change CS, where End date should be greater than Start date. can you help me please?
My Script:
Regards,
Lucky

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 08:15 AM
Hi,
Try adding below between line 10 and 11
var today_date_time_str = formatDate(startDate, g_user_date_time_format);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 09:22 PM
Hi Jaspal,
I am done with writing code for End date should be greater than Start date.
Now my query is:
Start Date should not be Past days
For this I have written script but it's not working.
Can you please correct it?
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 02:17 AM
Hello @Lucky1 DID YOU CHECK MY ABOVE RESPONSE FOR THE SAME .
YOU DONT NEED TO WRITE SCRIPT FOR THIS
1) Create a UI policy with condition as "start date is today " or "start date is less than today" and in the run script section execute if true you can write an addErrorMessage as
function onCondition() {
g_form.addErrorMessage('your_message');
g_form.clearValue('u_start_date');
return false;
}
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 08:20 AM
Hello @Lucky1 ,
No need to write a client script for this .
You can handle this via UI policies.
1) Create a UI policy with condition as "start date is today " or "start date is less than today" and in the run script section execute if true you can write an addErrorMessage as
function onCondition() {
g_form.addErrorMessage('your_message');
g_form.clearValue('u_start_date');
return false;
}
2)Create an onchange client script like below
unction onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//get the entered date string
var startDate = g_form.getValue('u_start_date');
var endDate = g_form.getValue('u_end_date');
var startDateValue = new Date(startDate).valueOf();
var endDateValue = new Date(endDate).valueOf();
//Compare the two numbers
if (startDateValue > endDateValue) {
alert('End date must be after start date.');
g_form.setValue('u_end_date','');
}
Hope this helps
Mark the answer correct if this helps you
Thanks