Forum Discussion

MalcolmMcDonald's avatar
Qrew Cadet
3 years ago

Jinja - Test for empty Date / DateTimes

Sometimes when I finally puzzle something out, I feel like celebrating by sharing -- in the hopes that it'll save someone else hours of forum trawling.

Use Case -- using pipelines to create an audit log table of changes to a production record.  Sometimes the record will have a date that will change, sometimes it'll have a date that was added.  Think:  Step A) customer ordered something, Step B) customer had the thing installed .. first time we get the record, there won't be an installed date, second time, there will.

I can pull the original installed date from step a using $prev -- eg a.$prev.installed_date  .. but if it's empty, pipelines will return an error 'Validation error: Invalid date/time value: '

If the date / datetime is empty, it has a string value of 'None'

In the pipeline, I set a conditional to an advanced expression evaluating to TRUE:

{% if a.$prev.installed_date|string != 'None' %}
{% else %}
{% endif %}​

I then know if the $prev date was set and can handle the next statements properly.

Happy to know if there are other, cleaner ways of handling this!

Malcolm McDonald

1 Reply

  • Hi Malcolm,

    Here are two different ways to make this work (a.entry is a date field):

    Let me know if you have any questions! I think this should fix your issue.

    Sean Connaughton