Actions for workflow state: Condition check

Need to write a condition on subtracting dates.
Here is the Usecase:

While uploading the document we will define the metadata expiry_date ex.“2023-05-10”, we need a condition that will check the current_date and expiry_date if current_date > expiry_date we need to a add tag called expired. but we don’t know how to write conditions using Django-built template tags and filters

Can someone guide me on this?
Thanks in advance :slightly_smiling_face:

{# grab the current date and time string #}
{% now "h:m m-d-y" as date_time_string %}

{# convert the date time string into a date object #}
{% set date_time_string|date_parse as now_date_object %}

{# convert the metadata expiration date string into a date object #}
{% set document.metadata_values_of.expiry_date|date_parse as expiration_date_object  %}
{% if now_date_object > expiration_date_object %}
True
{% endif %}
1 Like

@roberto.rosario Thanks for the Update :pray:

I tried with the above condition that has been provided, but I end with an error
Basically, we are adding a tag to the document on a state is exits with expiry condition

step1: we create workflow->state->action->condition

step2: Uploading document with the metadata
expirydate: 2023-05-01

step3:On state change i am getting error

Error in Logs:
File “/opt/mayan-edms/lib/python3.9/site-packages/dateutil/parser/_parser.py”, line 646, in parse

  • raise ParserError(“String does not contain a date: %s”, timestr)*
    dateutil.parser._parser.ParserError: String does not contain a date:

We found that metadata value is not fetching, so it is an empty string date parser failing it.
we tried with condition

{% set "2023-05-01"|date_parse as expiration_date_object  %}
{{expiration_date_object}}

it is working as expected, it is converting it as a date object but when we add

{% set document.metadata_values_of.expirydate|date_parse as expiration_date_object  %}
{{ expiration_date_object  }}

it is failing for this
I didn’t understand why it is not getting the metadata value
Any Help here?

step2: Image

step3 image

The same code is working on the document sandbox but when we tried in the workflow state action condition is not working