Solved

Liquid filters: date calculations

  • 20 December 2021
  • 2 replies
  • 243 views

Badge

Hi,

We are using service requests extensively.  We are using API PUT calls within ticket automators to set the due date on the service request according to a date field selected by the user within the service request.  This is working successfully.

I’d like to be able to set the response due date to one or two days prior to that due date, meaning I need to add -2 days to the due date.  For certain service requests, I’d like to be able to set the due date a week after the creation date, meaning I need to add 7 days to the ticket creation date.  I’ve spent days combing support materials and I can’t get anything to work.  This is my best current guess (I’m adding this as a note to the ticket to test the placeholders/filters):

 

Ticket created at {{ticket.created_at}}

One day later is {{ ticket.created_at | date_add: 1, "day" }}

 

It doesn’t work, it just gives me the ticket creation date twice and no errors:

Ticket created at Tue, 2021, Dec 14 at 7:58 AM GMT +1000
One day later is Tue, 2021, Dec 14 at 7:58 AM GMT +1000

I am aware the best way to do this sort of thing is with SLAs, priority matrix etc, but we are building a service desk for a non-tech support desk and their business model is slightly different.  

Anyone have any ideas?

icon

Best answer by dineshs 1 March 2022, 17:21

View original

2 replies

Badge

Hi Dinesh, thanks so much for taking the time to reply to me - much appreciated. After submitting this post, I submitted a support request to Freshservice and they advised me that date arithmetic is not yet possible in Freshservice.  None-the-less, I gave the code above a go (as you never know!), and this is what I got:

 

System added a private note in a few seconds (Wed, Mar 2 at 6:27 AM)

Ticket created at Wed, 2022, Mar 2 at 6:27 AM GMT +1000

One day later is 05-03-2022 6:27 am

 

….and hey presto it worked!  Now I need to figure out how this actually works so that I can put it to good use!  

THANK YOU

Badge +3

Hi EET,

 

Can you try the below code.

 

Ticket created at {{ticket.created_at}}

{% assign daysplus = 3 | times: 86400 %}

One day later is {{ ticket.created_at | date: "%s" | plus: daysplus | date: "%d-%m-%Y %l:%M %P" }}

 

Regards,

Dinesh S

Reply