Question

Expression Help

  • 21 September 2023
  • 4 replies
  • 170 views

Hello, 

I am trying to set a condition where that identifies if the time difference between a ticket being created and current time is greater than or equal to 4 hours. I have created the below expressions, but when I test the expression, I receive the Invalid Syntax - One of its operands is invalid error message. 

Expression:

if(diffInHours({{ticket.created_at}},{{current_date_and_time}})>=4,"TRUE","FALSE")


4 replies

Userlevel 7
Badge +11

Hi.

May I ask what are you trying to achieve?

In FreshService there’s a feature called Supervisor Rules.

It allows you to set and run events based on period of times.

As a matter of fact, there’s a standard condition called Hours since created:

 

You can perform then actions based on that.

 

Please be advised that this runs hourly, so, you should use additional conditions in order to ensure it runs once, unless desired.

 

 

Hope this helps.

 

Regards,

Userlevel 7
Badge +13

Hello, 

I am trying to set a condition where that identifies if the time difference between a ticket being created and current time is greater than or equal to 4 hours. I have created the below expressions, but when I test the expression, I receive the Invalid Syntax - One of its operands is invalid error message. 

Expression:

if(diffInHours({{ticket.created_at}},{{current_date_and_time}})>=4,"TRUE","FALSE")

Looks like you are missing ‘ and if you select output boolean you don’t need to have a IF 

diffInHours('{{ticket.created_at_iso}}','{{current_date_and_time_iso}}') >= 4

Remember you need to use ISO like this 

 

Or if you are after something like @eeha0120 say you can use Supervisor Rules

Userlevel 6
Badge +11

Hello, 

I am trying to set a condition where that identifies if the time difference between a ticket being created and current time is greater than or equal to 4 hours. I have created the below expressions, but when I test the expression, I receive the Invalid Syntax - One of its operands is invalid error message. 

Expression:

if(diffInHours({{ticket.created_at}},{{current_date_and_time}})>=4,"TRUE","FALSE")

Hi @Justin.Harvey - @Daniel Söderlund has provided a simpler solution if you are trying to arrange a sequence of events (e.g. status change to pending, send reply to requester etc).

If, however, you are looking for the corrected expression, here you go!  The unhelpful error you mention is almost always related to the wrong kind of quotes being placed around the values inside the expression.

Couple of things:

You can set Boolean as the output rather than an IF resolving to T or F.

I did some testing and unfortunately it appears as though this is a shortcoming of FS Expression node.  DiffInHours will not accept a parameter in testing - always throws an error - if you switch to a fully expressed date then it will do the calculation.

diffInHours('2023-08-13T11:45Z','2023-08-13T13:45Z')

diffInHours(‘start_date’,’end_date’)

 

Instead of trying to use [CURRENT_DATE_AND_TIME) I tried the functions NOW(timezone) or TODAY(timezone) and they also hit a wall bc we have no idea what FS will accept for timezone.  We only have the 1 example ‘Asia/Kolkata’ and ‘London’ or ‘UTC’ or ‘GMT’ are not accepted which seems odd to me.

Userlevel 7
Badge +11

Hello, 

I am trying to set a condition where that identifies if the time difference between a ticket being created and current time is greater than or equal to 4 hours. I have created the below expressions, but when I test the expression, I receive the Invalid Syntax - One of its operands is invalid error message. 

Expression:

if(diffInHours({{ticket.created_at}},{{current_date_and_time}})>=4,"TRUE","FALSE")

Hi @Justin.Harvey - @Daniel Söderlund has provided a simpler solution if you are trying to arrange a sequence of events (e.g. status change to pending, send reply to requester etc).

If, however, you are looking for the corrected expression, here you go!  The unhelpful error you mention is almost always related to the wrong kind of quotes being placed around the values inside the expression.

Couple of things:

You can set Boolean as the output rather than an IF resolving to T or F.

I did some testing and unfortunately it appears as though this is a shortcoming of FS Expression node.  DiffInHours will not accept a parameter in testing - always throws an error - if you switch to a fully expressed date then it will do the calculation.

diffInHours('2023-08-13T11:45Z','2023-08-13T13:45Z')

diffInHours(‘start_date’,’end_date’)

 

Instead of trying to use [CURRENT_DATE_AND_TIME) I tried the functions NOW(timezone) or TODAY(timezone) and they also hit a wall bc we have no idea what FS will accept for timezone.  We only have the 1 example ‘Asia/Kolkata’ and ‘London’ or ‘UTC’ or ‘GMT’ are not accepted which seems odd to me.

Hi Bryn.

Regarding the timezones, they’re currently listed here:

List of Time Zones Supported in Freshservice : Freshservice

 

Hope this helps.

 

Regards,

Reply