End date can not less than start date

Community Alums
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?

4 REPLIES 4

OlaN
Giga Sage
Giga Sage

Hi,

Depending on your requirement, you might not need to do any scripting.

You can for example create an UI policy that checks the two dates, and prohibits submitting the form if the End date is before the start date

Community Alums
Not applicable

Hi OlaN

 

can you give condition for UI policy?

Here is a simple example on what you can do (example is done with Service Catalog variables, but can be used in regular UI policy also).

 

variable-date-validation.png

NikhilKamlekar
Tera Expert

Hi @Community Alums ,

I have implemented this usecase, it's working fine.

You can achieve with the help of onChange Client Script on field End Date.

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    // var nowDate= new Date();

    var startDate = g_form.getValue('u_start_date');

    var endDate = g_form.getValue('u_end_date');

    if (endDate.valueOf() < startDate.valueOf());

    g_form.addErrorMessage('End date should not be less than start date');

    return false;

}
Testing:
NikhilKamlekar_0-1730718704266.png

 

Please mark my response as helpful and accept the solution, if it's resolved your query.