Solved

Expression Builder with Liquid expressions.


Userlevel 4
Badge +5

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

 

 

icon

Best answer by daniel.soderlund 19 May 2022, 11:38

View original

22 replies

Userlevel 3
Badge +3

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

Userlevel 4
Badge +5

Any ide on this ? 

Userlevel 7
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 4
Badge +5

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 4
Badge +7

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 4
Badge +7

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 3
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 4
Badge +5

@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 4
Badge +5

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 4
Badge +7

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 4
Badge +5

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 4
Badge +5

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. 

Userlevel 4
Badge +5

I solved this you need ‘’ when working with placeholders that could be empty/null 

 

@BrynCYDEF  was right all along :) 

Userlevel 4
Badge +7

LOL!  I feel super validated now! TY @daniel.soderlund made my day  :-D

Userlevel 2
Badge

Hello @daniel.soderlund ,

Good day! Please do check out the Expression builder explainer WOW session. Hope you will find it useful :D 

Here is the link 

Userlevel 4
Badge +5

Hello @daniel.soderlund ,

Good day! Please do check out the Expression builder explainer WOW session. Hope you will find it useful :D 

Here is the link 

Hi, thanks 

 

I’m starting to get the hang of it. 

 

I have this example, it checks if the requester is the manager for the one who is going to get the SI. 
As we we build our approval WFA with multipler step (ending WFA right away)   rather waiting on a conformation in the same WFA. This can check if it’s the first step. If it’s multistage as well. We have cases where a group of named approvers need to approve first and then the manager. 
We set the result of this as a TAG. 
 

if('{{P1.root.requester.reporting_manager_id}}' == '{{ticket.requester.id}}', 
if(regexMatch('{{ticket.tags}}', 'Step2'),
if('{{R1.manager_second}}' != '',
'Approved',
'Manager'),
if('{{R1.manager_first}}' != '',
if('{{R1.multi_approval}}' != '',
'Step2',
'Approved'),
'Step1'
)
),
if(regexMatch('{{ticket.tags}}', 'Step2'),
if('{{R1.manager_second}}' != '',
'Manager',
'Step2'),
if('{{R1.manager_first}}' != '',
'Manager',
'Step1')
)
)

I formatted it this way to see all the operands 

 

Userlevel 7
Badge +12

Wow guys!!! That all is impressive uses of the expression builder. I have had my first look at this as I needed a way to add a newly created Active Directory user to the correct OU based on what a user enters when filling out or Employee Onboarding request. Was able to use an if statement to verify that correct location and dynamically set the Path. 

Is going to be exciting to see more examples of how people have leveraged this functionality! Keep up the great work @daniel.soderlund @BrynCYDEF @ggallaway!!! 💪

Userlevel 7
Badge +12

Has anyone ran into a limitation on how many nested If() statements you can have as the false expression? I am trying to generate an expression that looks to see the value of a SamAccountName for Active Directory. I have parsed the JSON response into a useable field and am referencing the that field in this expression but I am getting an error when I try and save the node

Here is the expression (typed out in a code editor for better visibility)

And here is the error, where you can see the expression resolves and gives me the appropriate value but I am unable to save it.

@sanofar.allahpichai @daniel.soderlund @keefe.andrews any ideas? Thanks for the help team!!!

Userlevel 4
Badge +5

Has anyone ran into a limitation on how many nested If() statements you can have as the false expression? I am trying to generate an expression that looks to see the value of a SamAccountName for Active Directory. I have parsed the JSON response into a useable field and am referencing the that field in this expression but I am getting an error when I try and save the node

Here is the expression (typed out in a code editor for better visibility)

And here is the error, where you can see the expression resolves and gives me the appropriate value but I am unable to save it.

@sanofar.allahpichai @daniel.soderlund @keefe.andrews any ideas? Thanks for the help team!!!

Hi, Thanks for asking, I love this type of questions when I have to start thinking outside of the box and find solutions to problems. 

Here you have a start you could repeat. 
 

if('{{SAMaccountName}}' == substring('{{FirstName}}',0,1)+'{{LastName}}'+'1','True','False')


Found out if you like to use more then one Place Holder you use + or add text/number  + ‘text’


 

 

Userlevel 4
Badge +5

Ops , didn’t click Done and I got the same as you.  Feels like a bug 

 

This works just fine 

if('{{ticket.description}}' == substring('{{ticket.tags}}',0,1),'true','false')

Userlevel 4
Badge +5

@zachary.king Have you found any other solution for using more then one placeholder in a operand ? 

Userlevel 7
Badge +12

@zachary.king Have you found any other solution for using more then one placeholder in a operand ? 

Speaking with Freshservice support regarding this issue today. Will let you know what I find out.

Reply