Date comparison flow designer

levino
Giga Guru

Hi there

I have a catalog item with a DateTime variable.

 

i have also created  custom action 

(function execute(inputs, outputs) {
// ... code ...
  var currentdate = gs.nowDateTime();
   outputs.result = currentdate;
})(inputs, output

when i compare the 2 dates i get this error using the If condition in flow designer

if 'result' is at or after the ' catalog item datatime variable)''

Flow Designer: Operation(LucidChart.If$1.evalConditions) failed with error: com.snc.process_flow.exception.OpException: unable to evaluate condition for /if/_0_2394934e1b75a510e4a8cbb9274bcb96 = 27/03/2023 21:32:05 was not a datetime in format (ParseCaseSensitive(false)(Value(Year,4,10,EXCEEDS_PAD)'-'Value(MonthOfYear,2)'-'Value(DayOfMonth,2))'T'(Value(HourOfDay,2)':'Value(MinuteOfHour,2)[':'Value(SecondOfMinute,2)[Fraction(NanoOfSecond,0,9,DecimalPoint)]]))[Offset(+HH:MM:ss,'Z')['['ParseCaseSensitive(true)ZoneRegionId()']']]

1 ACCEPTED SOLUTION

Change script as below.

 

(function execute(inputs, outputs) {
var accStartDate=inputs.RequiredDate;
var currentDate=new GlideDate();
//gs.log('accStartDate'+accStartDate);
//gs.log('currentDate'+currentDate);
// var compareDate=accStartDate.compareTo(currentDate);
// gs.log('compareDate'+compareDate);
if(accStartDate<=currentDate){
outputs.result=true;
}else{
outputs.result=false;
}
})(inputs, outputs);

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

View solution in original post

22 REPLIES 22

Gopi Naik1
Kilo Sage

Hi @levino ,

 

Hope below conversation will help you.

https://www.servicenow.com/community/now-platform-forum/flow-designer-debug-if-condition-error-when-...

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

Gopi Naik1
Kilo Sage

As a solution pass the variable value as a input to custom action and compare that value with current date in custom action and return flag.

//(-1) accStartDate is before currentDate
  //(=0) accStartDate is equal currentDate
  //(+1) accStartDate is after currentDate

  var accStartDate = inputs.accStartDate
  var currentDate = new GlideDate();
  var compareDates = accStartDate.compareTo(currentDate)

  if (compareDates <= 0){
      outputs.result = true;
      //gs.log('DEBUG (Date Comparison): ' + compareDates);
      } else {
      outputs.result = false;
      //gs.log('DEBUG (Date Comparison): ' + compareDates);
  }

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

Hi Gopi

When i create the input variable  ( service catalog variable) to compare with current date - snippet as per below

or i just use the script as above to define both variables

 

Thanks

Levino

 

 

levino_0-1679958524151.png

 

Hi @levino ,

 

Yes you should create the input variable in custom action as per the snippet you added. And need to use that input variable value in script. For example if you created a variable with name requested_utul then use below code.

var inputVal=inputs.requested_util;

var currentDate=new GlideDate();

var compareDate=inputVal.compareTo(currentDate);

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi