MattV
11 days agoQrew Member
Auditing field changes using Pipelines & Jinja
I'm using Pipelines to track changes on hundreds of fields in a table. The step that writes a summary of the changes to a rich text field uses Jinja that looks like this:
{% set fields = [
('Field Name 1', a.field_name_1, a.$prev.field_name_1),
('Field Name 2', a.field_name_2, a.$prev.field_name_2),
...
('Field Name 200', a.field_name_200, a.$prev.field_name_200)
] %}
{% for i in fields %}
{% if i[1] != i[2] %}
{{'• <b><u>' ~ i[0] ~ '</u></b> changed from <b>' ~ (i[2] if i[2] is not none else '(null)') ~ '</b> to <b>' ~ (i[1] if i[1] is not none else '(null)') ~ '</b><br />'}}
{% endif %}
{% endfor %}
It works, however I'm questioning whether this can be done more elegantly, with Jinja or otherwise. I couldn't find a way to loop over the changed fields only in a generic fashion so I constructed tuples for each field. This makes the step very lengthy and difficult to find what I need; additionally my browser becomes sluggish when working with the Pipeline.
I appreciate any recommendations here.