Forum Discussion

CharlesDulaney's avatar
CharlesDulaney
Qrew Member
5 months ago

Jinja IF/Else with some math

I have a pipeline snippet below that functions as require, however, I have two issue that I cannot get past.

The duration code below stems from an actual duration field between two dates plus days(1) to capture first and last day.

The snippet is part of a larger Outlook channel HTML email

/// SNIPPET ///

{# Duration between 2 dates #}
{% if a.duration>0 %}
Duration: {{a.duration}} Day(s)
{% else %}
{% endif %}

/// RESULTS ///

Duration: 86400000 Day(s)

/// Issue #1 ///

No matter what I try, I cannot deduce the milliseconds to actual days. Dividing my duration by 86400000 should give me 1 Day, I simply cannot get the jinja code correctly update to achieve this result.

/// Issue #2 ///

The snippet provides a line feed or break regardless if the statement is true or false.



------------------------------
Thank you so much,

v/r,
Chuck
------------------------------

11 Replies

  • How are you trying to convert it? Something like: Duration: {{a.duration / 86400000}} Day(s) works when I test it. You can try {{a.duration|int / 86400000}} to see if that works as well. Worst case you could always make a formula-text field in your record that builds that Duration: Days(s) string and then just populate the email with that value as well instead of converting in the PIpeline. 



    ------------------------------
    Chayce Duncan
    ------------------------------
    • CharlesDulaney's avatar
      CharlesDulaney
      Qrew Member

      Neither scenario works, Invalid Template...

      Not sure that it matters, the email is a callable pipeline.

      I think you're right, the time I put into trying to get this resolve would have been better spent converting it in the record.



      ------------------------------
      Thank you so much,

      v/r,
      Chuck
      ------------------------------

      • ChayceDuncan's avatar
        ChayceDuncan
        Qrew Captain

        Strange. I am using the new Pipelines editor and I have it setup like this: 

        Where dur_1 is a duration field writing to a text field. When I put a duration of 2 days in dur_1 the pipeline process and I get the following with no issue/errors



        ------------------------------
        Chayce Duncan
        ------------------------------