Forum Discussion

ShaneMiller1's avatar
ShaneMiller1
Qrew Cadet
2 years ago

Pipelines - previous value and current value

Hello, 

I have read up on all the community topics that I can in regards to pipelines and prev values/ current values. I have read through most of the Jinja2 documentation.
From all that I have read, I have created the following jinja2 code within an update step for a field type Text - Multi-line:
{% if a.dba != a.$prev.dba %}
_dba changed from {{ a.$prev.dba }} to {{ a.dba }}
{% endif %}
{% if a.Tax_ID != a.$prev.Tax_ID %}
_Tax ID changed from {{ a.$prev.Tax_ID }} to {{ a.Tax_ID }}
{% endif %}

With this in place, if I change dba and tax_id and then click save, this appears:
_dba changed from 4 to 5_Tax ID changed from 4 to 5
Perfect!!! Exactly what I wanted. I then have a formula text that formats the above field. 

However, if I add more if statements to this jinja2 code:
{% if a.dba != a.$prev.dba %}
_dba changed from {{ a.$prev.dba }} to {{ a.dba }}
{% endif %}
{% if a.Related_Broker != a.$prev.Related_Broker %}
_Related Broker changed from {{ a.$prev.Related_Broker }} to {{ a.Related_Broker }}
{% endif %}
{% if a.Related_GA != a.$prev.Related_GA %}
_Related GA changed from {{ a.$prev.Related_GA }} to {{ a.Related_GA }}
{% endif %}
{% if a.Tax_ID != a.$prev.Tax_ID %}_Tax ID changed from {{ a.$prev.Tax_ID }} to {{ a.Tax_ID }}
{% endif %}

With this code in place, if I change dba and tax_id and then click save, only this appears:
_dba changed from 5 to 6

it completely disregards the fact that I also changed the tax_id. As I understand it, Pipelines should evaluate all the {% if %} statements separately and continue even if any individual if statement is false. Each {% if %} block is independent of the others, and the code inside each block will be executed only if the condition is true.

Am I doing something wrong, misunderstanding something, or is Pipelines at fault for not rendering the environment properly?
Any ideas?



------------------------------
Shane Miller
------------------------------
  • Shane, formula IF is evaluating statements from top and stops execute if statement = True.

    In your case if you have this statement as one, it finds first TRUE, execute it and drop.

    {% if a.dba != a.$prev.dba %}

    If you want to evaluate other part of IF, it needs to be separate to different steps in your Pipeline.



    ------------------------------
    Adam Krzyzanek
    ------------------------------
    • ShaneMiller1's avatar
      ShaneMiller1
      Qrew Cadet

      Hey Adam, 

      Thank you for responding. 
      The only odd thing is, I don't think what you say is 100% accurate. As stated in my original post, when I did only two "if statements", and changed dba and tax ID, it did in fact run through both of if statements and executed the "then" line of code for both. That's where I am confused. 
      It seems to be that it only stops evaluating if statements if one of them is false? Is there any documentation to back up what you have stated?



      ------------------------------
      Shane Miller
      ------------------------------