- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 02:34 PM - edited 04-15-2024 02:37 PM
Hi,
I have requirements as below:
1. 'Expected Start Date' should be selected after 7 days from today (if not then show error message and clear the value)
2. 'Expected Completion Date' should be after 'Expected Start Date'. (if not then show error message and clear the value)
For the first requirement: I created a UI Policy which is working fine.
For the second requirement: I created a client script, which is getting Invalid Date from Start date in the script and not working.
Can anyone please help me fix the above issue.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 09:58 PM
Hi @Nipan1 ,
For the second requirement also you can create a UI Policy and add the below condition.
date_2 should be "Expected Completion Date" and date should be "Expected Start Date".
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.
Regards,
Deborah Brown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 03:44 PM
Hello @Nipan1 is there a reason you are not using UI policy for your second requirement? Here is a screenshot showing how I implement that on the change record.
If this helped please mark it 👍 helpful or ✅ solution at appropriate
--
Bala Guthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 06:37 PM
Hi @Nipan1 ,
1. 'Expected Start Date' should be selected after 7 days from today (if not then show error message and clear the value)
If you use UI Policy -> with condition Start date is not Empty && End Date - Less than - 7 - days - after -Start date and script as below
function onCondition() { g_form.addErrorMessage('End Date should be 7 days after start date'); g_form.clearValue('u_end_date'); }
Problem : g_form.showFieldMsg may not be work and error message remains on form.
If you use Onchange() Client script you can show g_form.showFieldMsg under field which looks good. try below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } var start = new Date(g_form.getValue('u_start_date')); var end = new Date(g_form.getValue('u_end_date')); var sevenDaysLater = new Date(start.getTime() + 7 * 24 * 60 * 60 * 1000); if (end < sevenDaysLater) { g_form.showFieldMsg('u_end_date','End date should be after 7 days of start date','error',false); g_form.setValue('u_end_date', ''); } }
2. 'Expected Completion Date' should be after 'Expected Start Date'. (if not then show error message and clear the value)
Create an onChange script for your start_date and end_date fields.
//start_date onChange Function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var nowDate = new Date(); //Creates a JS date object for right now
var checkStart = new Date(newValue); // Create a JS Date object using the desired start_date field (from newValue parameter)
if (nowDate >= checkStart){ //JS Date objects compared
alert('You cannot select today or a day in the past');
g_form.setValue('start_date','');
}
}
//end_date onChange Function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var startDate = new Date(g_form.getValue('start_date')); //get the value of the start_date field using the g_form.getValue method
var checkEnd = new Date(newValue); // create a new JS date from the desired end_date field (using newValue parameter)
if (checkEnd <= startDate){ //Again - a simple JS Date object comparison
alert('End date must be after start date');
g_form.setValue('end_date','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 09:15 PM
Hi @Sumanth16,
I tried the above solution you mentioned, but they are not working. Still getting invalid dates while checking the dates in the scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 09:58 PM
Hi @Nipan1 ,
For the second requirement also you can create a UI Policy and add the below condition.
date_2 should be "Expected Completion Date" and date should be "Expected Start Date".
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.
Regards,
Deborah Brown