We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

End date Greater than Start date

Not applicable

Created two Date/time fields in format DD:MM:YYYY HH:mm:ss

End date(DD:MM:YYYY HH:mm:ss) can not be earlier than Start date(DD:MM:YYYY HH:mm:ss)??

 

Can anyone give script for this?

1 ACCEPTED SOLUTION

PavanK960672992
Mega Patron

Hi @Community Alums ,

If you have any issue on UI policy you can try Onchange client script on end date as below.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var start = g_form.getValue('u_start_date'); //add start date field name
    if (newValue <= start) {
        g_form.addErrorMessage('End Date should be Greater than Start Date ');//add message here
        g_form.clearValue('u_end_date'); //add end date field name
    }
}

Screenshot:

Screenshot (702).png 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

10 REPLIES 10

brianlan25
Kilo Patron

PavanK960672992
Mega Patron

Hi @Community Alums ,

1. Create UI policy as below condition and script.

Script: 

 

function onCondition() {
    g_form.addErrorMessage("Enter valid date, You cannot select date less than start date");
    g_form.clearValue('planned_end_date');
}

 

 

Screenshot (699).png

Screenshot (700).png

you can achieve it through onchange client script as well.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Not applicable

Hi Pavan Kumar , I tried with above condition but not working.

Not applicable

AkhilaNaradi_0-1677690753309.pngAkhilaNaradi_1-1677690772122.pngAkhilaNaradi_2-1677690791328.png