The Zurich release has arrived! Interested in new features and functionalities? Click here for more

compare two date fields

cray
Kilo Contributor

i have two date fields

1)start date

2)end date

if start date is greater than end date,abort the form from submission

please help me with the businees rule script..

12 REPLIES 12

BALAJI40
Mega Sage

var result = gs.dateDiff (current.start_date, current.end_date, true);


if(result < 0 )


current.setAbortAction(true);


Omar22
Kilo Contributor

Did The Trick!

anjiadmin
Tera Expert

function onSubmit()


  {


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


  var sdt = g_form.getValue('u_start_date')



  if(edt < sdt)  


  {


  alert("Please enter date that is more value than current date");


  return false;


  }


  else


  {


  alert("U entered correct date");


    return true;


  }


Please help me 

https://community.servicenow.com/community?id=community_question&sys_id=aa6f9ebb1b23d810d2ccea89bd4bcbef

dasthu1
Kilo Expert

HI Prashanth,



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


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


  return;


  }


  var toDate   = g_form.getValue('u_to_date');



  if(toDate==null || toDate==''){


  g_form.addErrorMessage('Please select the Date first');



  return;


  }


  else{


  var fromDate = new Date(newValue);


  var to_Date = new Date(toDate);


  if(fromDate>to_Date){


  g_form.addErrorMessage("to date should be greater than from date plz select from date should be less than to date");


  g_form.setValue('u_from_date',oldValue);


  return;


  }else{


  g_form.clearMessages();


  }


  }


}


try with as tiz with your field names:::


Thanks,
Dasthagiri K



PS: Hit like, Helpful or Correct depending on the impact of the response.