Skip to main content
Question

Expression Help

  • September 21, 2023
  • 4 replies
  • 288 views

Justin.Harvey
Apprentice
Forum|alt.badge.img

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")

Did this topic help you find an answer to your question?

4 replies

eeha0120
Skilled Expert
Forum|alt.badge.img+12
  • Skilled Expert
  • 732 replies
  • September 21, 2023

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,


Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14
Justin.Harvey wrote:

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


Forum|alt.badge.img+11
  • Skilled Expert
  • 170 replies
  • September 29, 2023
Justin.Harvey wrote:

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.


eeha0120
Skilled Expert
Forum|alt.badge.img+12
  • Skilled Expert
  • 732 replies
  • October 9, 2023
BrynCYDEF wrote:
Justin.Harvey wrote:

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