Question

Expression Builder with Liquid expressions.


Userlevel 2
Badge +3

Hello, 

Been testing the new Expression Builder block and found some ups and some downs. 

I created this expression using Liquid and the test gives me OK on it but I can’t save it. I get this when I click on done. 
Invalid Syntax - One of its operands is invalid.

 

{% assign home = "no" %}{% if {{home}} == "no" %}"no"{% else %}"yes"{% endif %}

 

 

My goal is something like this, create a 

{% if {{ticket.tag}} contains "ApprovalStep2" %}{{R3.approver1}},{{R3.approver2}},{{R3.approver3}},{{R3.approver4}}{% else %}{{R2.approver1}},{{R2.approver2}},{{R2.approver3}},{{R2.approver4}} {% endif %}

 

This is part of a Approval flow.  

My first action sets TAGS with this 

https://gist.github.com/varazir/f9c714f8193e45531e8c5fbcdc57e61b

Next action is to send approval message based on “to be approved by”-types there are. Using tags for conditions and don’t want to make 2 setups with send approval actions. 

 

( I wish there was a API option in the body when you send a note  “approveby”: “everyone” ) 

 

 


12 replies

Userlevel 3
Badge +3

Hey @prats!
By any chance, did you encounter this scenario during your configuration? 

Userlevel 2
Badge +3

Any ide on this ? 

Userlevel 6
Badge +12

I have not had a chance to utilize this feature but I appreciate you pointing out some possible limitations. Hopefully these can get recognized and worked out to better the experience. We love new functionality though it sometimes comes at a price lol.

Userlevel 2
Badge +3

I have not had a chance to utilize this feature but I appreciate you pointing out some possible limitations. Hopefully these can get recognized and worked out to better the experience. We love new functionality though it sometimes comes at a price lol.

Ya I was looking forward to do some really cool stuff with an approval flow. My plans is one WFA for multistage approval with exception for managers and named approvers. I can do it with using Liquid  to set tags before this update but I wish I could use the this block to create a list of approvers to send to.

Userlevel 3
Badge +6

Hi @daniel.soderlund 

re:    Invalid Syntax - One of its operands is invalid.

I have discovered that this unhelpful error means your expression is missing the single quote that must wrap each of the parameters.

 

{% if {{ticket.tag}} contains "ApprovalStep2" %}{{R3.approver1}},{{R3.approver2}},{{R3.approver3}},{{R3.approver4}}{% else %}{{R2.approver1}},{{R2.approver2}},{{R2.approver3}},{{R2.approver4}} {% endif %}

 

Is this your actual expression from the Ticket Automator?  If so you are missing the round brackets and that 1st parameter should be {{ticket.tags}} -- also I’m not sure what the % are for - did you put them in or did the Expression builder?

Are you trying to do a concatenation?  There is a function for that    concat()

Also, did you put the Object Reader in front of this Expression so that it will have access to the Approver variables you reference?

 

HTH

Bryn @ CYDEF

 

Userlevel 3
Badge +6

I was pretty proud of this one - it will search the {{ticket.description}} field and pull out the Client Name which it finds after the words “Client Name :”  and before “Environ”.  Works great!

 

substring('{{ticket.description}}', (indexOf('{{ticket.description}}','Client Name :',0)+14), indexOf('{{ticket.description}}','Environ',0))

 

Expected Output = String

Results = Company Name 

Userlevel 2
Badge +5

I have been struggling with some advanced expressions as well. Seeing similar errors and having trouble pinpointing the issue. It would be nice to know if a specific library is being used to provide this functionality (similar to how you can view the liquid documentation) so that we can understand the root limitations beyond what is provided in the FreshService documentation.

 

Userlevel 2
Badge +3

@BrynCYDEF  The % is used in Liquid reference (shopify.dev) The expression it self is sound. If you look at my first example that works.  I guess I could use regexp as  “contains” 

As tags are a array you can’t use == as an operator. 

Userlevel 2
Badge +3

I wish I could change the topic of this post to Buggs in Expression block/condition. 

Found another.

This fails when it’s running, I think it’s due to one of the fields in the custom object is empty. 
if({{R2.approver_1}} != {{ticket.requester.id}} && {{R2.approver_2_optional}} != {{ticket.requester.id}} && {{R2.approver_3_optional}} != {{ticket.requester.id}} && {{R2.approver_4_optional}} != {{ticket.requester.id}}, true,false)

 

This looks OK and the test say it’s true/false in a condition 

regexMatch('{{R2.approver_1}} {{R2.approver_2_optional}} {{R2.approver_3_optional}} {{R2.approver_4_optional}}', '\b{{ticket.requester.id}}\b')

When I press done we get an error 

Invalid Syntax - Found more operands than expected.

Userlevel 3
Badge +6

Ah I see ty @daniel.soderlund - I’ve not used Liquid before so I don’t know the language at all.  I misunderstood and thought you were trying to use the Expression builder in the automator.

This fails when it’s running, I think it’s due to one of the fields in the custom object is empty. 
if({{R2.approver_1}} != {{ticket.requester.id}} && {{R2.approver_2_optional}} != {{ticket.requester.id}} && {{R2.approver_3_optional}} != {{ticket.requester.id}} && {{R2.approver_4_optional}} != {{ticket.requester.id}}, true,false)

 

Did the test results come back as  -1   ?  I discovered that means the value is not found in the test in the Expression builder node.

Maybe you could build a nested IF() instead of 1 giant IF()?

Userlevel 2
Badge +3

Ah I see ty @daniel.soderlund - I’ve not used Liquid before so I don’t know the language at all.  I misunderstood and thought you were trying to use the Expression builder in the automator.

This fails when it’s running, I think it’s due to one of the fields in the custom object is empty. 
if({{R2.approver_1}} != {{ticket.requester.id}} && {{R2.approver_2_optional}} != {{ticket.requester.id}} && {{R2.approver_3_optional}} != {{ticket.requester.id}} && {{R2.approver_4_optional}} != {{ticket.requester.id}}, true,false)

 

Did the test results come back as  -1   ?  I discovered that means the value is not found in the test in the Expression builder node.

Maybe you could build a nested IF() instead of 1 giant IF()?

Doing the express test in the condition and it say OK.  The issue I have figurer out is if a placeholder in a custom object is empty aka null the if() fails.

 

Userlevel 2
Badge +3

What it comes down to is

I have 4 ( or more ) placeholders with users. 
The fields can be null or have a value. 

Need to match them to the requester. 

Reply