- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi all,
I'm getting syntax error in Workflow for the following statement:
{% if everyThird == 1 and forloop.index >= 2 %}
But it runs fine here: https://jumpseller.com/support/liquid-sandbox/
In WorkFlow When I change it to:
{% if everyThird == 1 and forloop.index == 2 %}
It runs fine without any errors. Any ideas?
Complete code:
{% assign digits = Data.Invoice.AmountWithoutTax | split: '' %}{% assign pointer = digits.size | minus: 2 %}{% assign remainderP = digits.size | minus: 1 %}{% assign decPoint = digits[pointer] %}{% assign remainder = digits[remainderP] %}{% capture new_var %}{{ decPoint }}{{ remainder }}{% endcapture %}{{ "$" }}{% for digit in digits %}{% assign everyThird = digits.size | minus: forloop.index | modulo: 3 %}{% if everyThird == 1 and forloop.index >= 2 %}{% if forloop.index >= pointer %}{{ new_var }}{% break %}{% endif %}{{ digit | prepend: ',' }}{% else %}{{ digit }}{% endif %}{% endfor %}
Thanks in advance!
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
@Patrick Oh! It was for an email! Yes, ALWAYS disable the editor. Verify what the email will look like externally, but disable the editor in the WF app. That thing has messed with me too many times.
When I try to write Liquid scripts outside the editor and then copy and paste, things go really bad.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
So couple of things:
1. What is the syntax error you are getting?
2. If I query for exactly one invoice and use the following, it works:
{% assign digits = Data.Invoice[0].AmountWithoutTax | split: '' %}
{% assign pointer = digits.size | minus: 2 %}
{% assign remainderP = digits.size | minus: 1 %}
{% assign decPoint = digits[pointer] %}
{% assign remainder = digits[remainderP] %}
{%- capture new_var -%} {{ decPoint }}{{ remainder }} {%- endcapture -%}
{{ "$" }}
{%- for digit in digits -%}
{%- assign everyThird = digits.size | minus: forloop.index | modulo: 3 -%}
{%- if everyThird == 1 and forloop.index >= 2 -%}
{%- if forloop.index >= pointer -%}{{ new_var }}{%- break -%}
{%- endif -%}
{{ digit | prepend: ',' }}{%- else -%}{{ digit }}{%- endif -%}
{%- endfor -%}
3. Seeing the output of your code, you can just do this:
$ {{Data.Invoice[0].AmountWithoutTax | times: 100 | money}}
I honestly don't know why the 'money' filter divides the original amount by 100, but if you do the 'times: 100', it should come out right.
Hope this helps.
@Patrick wrote:Hi all,
I'm getting syntax error in Workflow for the following statement:
{% if everyThird == 1 and forloop.index >= 2 %}
But it runs fine here: https://jumpseller.com/support/liquid-sandbox/
In WorkFlow When I change it to:
{% if everyThird == 1 and forloop.index == 2 %}
It runs fine without any errors. Any ideas?
Complete code:
{% assign digits = Data.Invoice.AmountWithoutTax | split: '' %}{% assign pointer = digits.size | minus: 2 %}{% assign remainderP = digits.size | minus: 1 %}{% assign decPoint = digits[pointer] %}{% assign remainder = digits[remainderP] %}{% capture new_var %}{{ decPoint }}{{ remainder }}{% endcapture %}{{ "$" }}{% for digit in digits %}{% assign everyThird = digits.size | minus: forloop.index | modulo: 3 %}{% if everyThird == 1 and forloop.index >= 2 %}{% if forloop.index >= pointer %}{{ new_var }}{% break %}{% endif %}{{ digit | prepend: ',' }}{% else %}{{ digit }}{% endif %}{% endfor %}
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
Hi @bmesa
The error I got is:
Liquid syntax error: Unexpected character & in "everyThird == 1 and forloop.index >= 2"
I have tried:
{{Data.Invoice.Balance | money: 'USD' }}
it works, the output is: $16,600,000.00, I've suggested this to a customer, but he's running into issues as well, that's why I am trying to come up with an alternative.
Let me try your suggestion, thank you so much!
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
Interesting error, my only suggestion is copy and paste the script into notepad or some text editor and convert to plain text. There might be an invisible special character somewhere. Could be the '>' character, which is why it works if you use '=='. '>' is '>' encoded and '=' is '=' encoded. Other than that...support ticket.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
After a few attempts, I'm going the support route. Thanks again!
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
@bmesa I figured it out. Liquid templating code somehow converted ">=" into ">=" and therefore it complains about "&" when I run it. In the mail editor, check the box "Disable Editor", change ">=" back to ">=", save and run and it works.
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
@Patrick Oh! It was for an email! Yes, ALWAYS disable the editor. Verify what the email will look like externally, but disable the editor in the WF app. That thing has messed with me too many times.
When I try to write Liquid scripts outside the editor and then copy and paste, things go really bad.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
@bmesa I'll check that box every time now!
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Liquid Syntax
which box?