I cannot get the "End date" before "start date" client script to work.

mandie
Kilo Contributor

This is my current code for a catalog client script:

function onSubmit()

{

//g_form.addInfoMessage("Before error");

var datefrom = g_form.getValue('u_it_email_ooo_datefrom');

var dateto = g_form.getValue('u_it_email_ooo_dateto');

if(datefrom > dateto)

{

g_form.clearMessages();

g_form.addErrorMessage("End date cannot occur before start date.");

return false;

}

}

It works fine when the end date is before the start date, but only when they are in the same month.

When I change the end date to a day in the month before the start date, it allows me submit. Can anyone help? This is quite urgent because i have a meeting with my manager to put this through to our live system today and cannot get it to work properly!! Please help!!!

7 REPLIES 7

Cheers Darren 🙂

 

Raj

mattrom1
Giga Expert

This works for me on Service Portal



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


g_form.hideFieldMsg('end_date', true);


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


if ( newValue < startDate){


g_form.showFieldMsg('end_date',"End date can't be prior to Start date ",'error');


}




    //Type appropriate comment here, and begin script below


   


}


Have you modified this script to account for users with a different date/time format?  Someone with a format of dd/MM/yyyy will receive the error message if the start/end dates span multiple months (Example: Start Date = August 30: 30/08/2018, End Date = September 1: 01/09/2018)