Question

Expression Builder Syntax

  • 27 July 2022
  • 7 replies
  • 920 views

Userlevel 1
Badge

I have a subject line that comes in as zero|one|two|three|date.  I am trying to create an expression that will take the date and convert it to an ISO date to be used later.  so far i have the following

{% assign subject = {{ticket.subject}}%}{% assign date= subject | split: "|" %}{{date[4]}}

This will seem to work in an app but not the expression builder to get the date. First problem

If I can get the correct date extracted I planned on doing the following:

lets say the date I extract is 07292022, i could use 

date(2022,07,29) to convert the date, this works the expression builder and will return a good date but when I use

date(substring('07292022',4,8),substring('07292022',0,2),substring('07292022',2,4)) it does not work. Second problem

I then planned on using the split function from the first problem to insert into the substrings where the date is but I just cant figure out the syntax of liquid and the expression builder.


7 replies

Userlevel 1
Badge

I’ve made some progress, the following expression returns correctly when testing

{% assign subject = {{ticket.subject}} | split: "|" %} concat(concat(concat(concat(substring('{{subject[4]}}',4,8),'-'),substring('{{subject[4]}}',0,2)),'-'),substring('{{subject[4]}}',2,4))

but when I click done I get the error

Invalid Syntax - invalid operator found.

sample data - {{ticket.subject}} = .zero|one|two|three|07292022|five

Userlevel 7
Badge +16

Hello @rwelsford, A number of us have been having issues with the Expression Builder allowing us to save our complex expressions. The Invalid Syntax error seems to be a common error even if the expression resolves correctly. I have a ticket that has made its way to the Freshservice Development Team to try and fix this bug. Hopefully we have a resolution soon.

Userlevel 1
Badge

@zachary.king thanks for the heads up, I have been banging my head against the wall for days trying to get complex expressions working.  I will also open a ticket

Userlevel 7
Badge +13

Hello, 

I have issue having more then one placeholder after each other. 
Something like this 
if(‘{{placeholder}}{{placeholder}}’ == ‘22’,’{{placeholder}}-{{placeholder}}’,’2’}}

This should be 2-2 or 2 but it fails. 

Userlevel 1
Badge

Well, I opened a support ticket for this and found that the placeholder {{ticket.subject}} cannot be used in an Expression Builder.  I then tried to add a public note with {{ticket.subject}} (Which works fine) and then use {{ticket.last_public_note}} and that did not work either.  I have asked support to let me know what placeholders cannot be used in an Expression Builder

Userlevel 7
Badge +16

Hello, 

I have issue having more then one placeholder after each other. 
Something like this 
if(‘{{placeholder}}{{placeholder}}’ == ‘22’,’{{placeholder}}-{{placeholder}}’,’2’}}

This should be 2-2 or 2 but it fails. 

You could try using the “append” method for Liquid placeholders, that is what support has given me as a way to use more than one placeholder.

https://shopify.github.io/liquid/filters/append/

Badge

Well, I opened a support ticket for this and found that the placeholder {{ticket.subject}} cannot be used in an Expression Builder.  I then tried to add a public note with {{ticket.subject}} (Which works fine) and then use {{ticket.last_public_note}} and that did not work either.  I have asked support to let me know what placeholders cannot be used in an Expression Builder

I had the same problem with this simple string:

'Ticket number: {{ticket.id}} - Subject: {{ticket.subject}}'

The Test was fine and passed but when saving it failed with: Invalid Syntax - invalid operator found.

The strange thing is that if you put a final hyphen it works:

'Ticket number: {{ticket.id}} - Subject: {{ticket.subject}}'’

The final hyphen is visible in the output but at least it works...

Reply