Restrict end date based on start date?

rambabu1
Giga Expert

In form 2 date/time fields.

1 for Start date & 2 is End date.

start date/time must be today or future.

End date/time cannot be same & past  from start date?

1 ACCEPTED SOLUTION

Kunal Varkhede
Tera Guru

Hi,

 

In addition to above, also check below

Simply done Using UI Policy and OnSubmit client script.

 

1)OnSubmit Client script

Check Start Date is less than End Date

find_real_file.png

function onSubmit() {
    var start_date = g_form.getValue('u_start_date'); //pass here your field backend name
    var end_date = g_form.getValue('u_end_date');//pass here your field backend name
    if (end_date < start_date) {
        alert("Start date is gretter than End Date ");
        return false;
    }
}

2)UI Policy

i) To check Start date is not past date must be future.

If it is past then clear that value using UI Policy.

find_real_file.png

ii)In UI Policy Action Clear date 

find_real_file.png

 

iii) In script Section of Ui Policy

find_real_file.png

 

 

Check the Output in below screenshot

 

find_real_file.png

find_real_file.png

Please mark correct/helpful answer if it help you in any way.

Thanks,

Kunal

View solution in original post

12 REPLIES 12

Tejas Tamboli
Giga Guru

Hello rambabu,

No need to write BR or Client Script.

You can achieve this from UI Policy. Only you need to create two UI Policy.

For Start Date,

In my case - Start Date is my From Date.

find_real_file.png

 

find_real_file.png

 

For End Date,

In my case - End Date is my To Date.

find_real_file.png

find_real_file.png

 

 

 

I hope this will help you.

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response useful to you and help others to find information faster.

Thanks,
Tejas

Kunal Varkhede
Tera Guru

Hi,

 

In addition to above, also check below

Simply done Using UI Policy and OnSubmit client script.

 

1)OnSubmit Client script

Check Start Date is less than End Date

find_real_file.png

function onSubmit() {
    var start_date = g_form.getValue('u_start_date'); //pass here your field backend name
    var end_date = g_form.getValue('u_end_date');//pass here your field backend name
    if (end_date < start_date) {
        alert("Start date is gretter than End Date ");
        return false;
    }
}

2)UI Policy

i) To check Start date is not past date must be future.

If it is past then clear that value using UI Policy.

find_real_file.png

ii)In UI Policy Action Clear date 

find_real_file.png

 

iii) In script Section of Ui Policy

find_real_file.png

 

 

Check the Output in below screenshot

 

find_real_file.png

find_real_file.png

Please mark correct/helpful answer if it help you in any way.

Thanks,

Kunal

asifnoor
Kilo Patron

Hi,

Refer to my article, where i have provided code sample to restrict this. Refer to this.

https://community.servicenow.com/community?id=community_article&sys_id=a26dac761b4e8010a59033f2cd4bc...

Mark the comment as a correct answer and helpful if this answers your question.