Forum Discussion

JimHarrison's avatar
JimHarrison
Qrew Champion
8 months ago

Jinja If else statement syntax

In case anyone else is looking for a solution to entering a conditional statement into a Pipeline as an out put value, here is what I learned today.

Below is the syntax entered into the place where the {{ c.values }} are put in the Pipelines Designer page. If anyone knows what these inputs are named please tell me.

{% if step.fieldname is gt(0) %} {{step.fieldname * -1}} {% else %} 0 {% endif  %}

Explanation: The statement above is an if : else statement. {% %} these things signify the conditional statement part and {{ }} these are the values the field gets if the condition is met.

If the fieldname is greater than 0
{% if step.fieldname is gt(0) %}

then enter the value from fieldname from a previous step times negative 1
{{step.fieldname * -1}} 

else do the next thing, which in this case is enter 0 into the fieldname from a previous step
{% else %}

finally end the if statement
{% endif  %}

I looked around and couldn't find anything useful so here's a little nugget.



------------------------------
Jim Harrison
transparency = knowledge + understanding : The Scrum Dudes
------------------------------

1 Reply

  • I couldn't find anything either, but somehow have this in my notes, which basically echoes what you have. I can't remember where I got this, but I am pretty sure I found it on Quickbase Junkies page, so give her the credit! Unless it's wrong, then it probably wasn't her :)

    //Below is general if/else in Pipelines with jinja. can do this for setting specific fields

    {% if  some_condition %} {{do something }}
    {% elif  some_other_condition %} {{do something }}  
    {% else %} {{do something }}
    {% endif %}

    I also have these notes about mapping null fields:

    When updating a record and mapping some fields to others, if the source field is null, Pipelines will not map that field, it skips it. However, if the goal is to map exactly, even a blank field, then use the following (using field date as an example):

    {% if a.date is none %}
    {{ CLEAR }}
    {% else %}
    {{a.date}}
    {% endif %}

    Could also be written in the condensed format as (I use this, simple and quick):

    {{ CLEAR if a.date is none else a.date }} 



    ------------------------------
    Mike Tamoush
    ------------------------------