Dynamic document status based on metadata type field(s)

Hi every one,

This post is to help fellow community members in creating dynamic status for documents (at least the work around I found).

The Case:

I have multiple legal documents and licenses that may expire after a period of time or as per an expiry date field in their metadata, and I need to flag (tag) them, index them, and notify when they near their expiry.

The solution:

I used the workflow module as the following:

1- Create a states as follows:
Check
Active
Expired
Start (initial state)
2- Make transitions to and from each state to Check state (except Start which will have only Start to Check transition).
Active to check and expired to check transitions should have a trigger (document meta data edited)
Start to check ( i added triggers: workflow instance initiated, metadata added, meta data changed)
3- Add actions to states as follows:
State: Check: Remove tag ‘Expired’ (on exit) , Remove tag ‘Active’ (on exit), Remove tag ‘Near Expiry’ (on exit)
State: Active: Add tag ‘Active’ (on entry) - no conditions, Add tag ‘Near Expiry’ (on entry) - add condition (I added if its within 30 days of expiry).
State: Expired Add tag ‘Expired’ (on entry)
4- Create two escalations for the check state
priority 0: duration 1 minute: condition if document is not expired: transition to Active State
priority 1: duration 1 minute: condition if document expired: transition to Expired State.
5- Create 1 escalation for Active state: duration 1 day with no condition: transition Active to check.
6- I created an escalation for the start state to send it to check after 30 minutes ( to make sure no documents stuck there for whatever reasons).
7- No need for any escalation for Expired state.

Summary:

the above configuration will:
1- Check my documents daily for expiry.
2- Flag them as active, Active with near expiry, expired.
3- Notify when they are nearing their expiry.
4- Recheck them if metadata is changed,
5- Stop checking when documents expire.

You can use the same methodology for other dynamic procedures but:

1- I don’t have any idea about the performance cost with huge number of documents being checked automatically but luckily the one day period is distributed throughout the day since it depends on the date and time of the upload. (still its functional for my test scenario and the expected amount of documents I have, and I can add a little more resources to the server if I need)
2- I appreciate any senior with Mayan to point out if its a good solution or if it has gaps ( and of course if there is a better way to do it).

Hope this is helpful to others.

2 Likes

Hi Zee,

Thank you for sharing your solution! I have a similar requirement for our legal department to send notifications when contracts are nearing expiration. Your approach looks very promising, but I would like to better understand the setup, especially regarding how you configured the workflow.

Would it be possible for you to share some screenshots of the workflow states, transitions, and actions you’ve implemented? This would help me visualize the configuration and adapt it to our needs.

Hi amjamali,

Sorry for the delayed response:

please find the details below:

1- metadata (Start and End Dates):

2- I used the following regex to validate dates in the following format dd/mm/yyyy (it considers month days number and leap years for feb):

pattern: ^(?:(?:29([-./])02(?:\1)(?:(?:(?:1[6-9]|20)(?:04|08|[2468][048]|[13579][26]))|(?:1600|2[048]00)))|(?:(?:(?:0[1-9]|1\d|2[0-8])([-./])(?:0[1-9]|1[0-2]))|(?:29|30)([-./])(?:0(?:1|[3-9])|(?:1[0-2]))|31([-./])(0[13578]|1[02]))(?:\2|\3|\4)(?:1[6-9]|2\d)\d\d)$

3- I’ve created a work flow to track the state of the document:

4- I’ve created the following states (Start is the initial state):

5- I’ve created the following transitions (pay attention to the triggers):

6- I added actions for the active state (on entry) to add and remove tags as per expiry date validation (note: I’ve added a tag for near expiry “30 days before expiry”):

7- Likewise for the expired state:

8- I’ve added an escalation to the active state to send the document to the check state daily, so the workflow can check the expiry again, (I’ve added a condition for this escalation based on the expiry date to enhance performance so only documents near expiry will have this escalation active):

I’ve used this condition (it’s not pretty or efficient, but i’m still getting my head around this django template thing):

{% spaceless_plus %}
{% now “h:m m-d-y” as now_date_time_string %}
{% set now_date_time_string|date_parse as now_date_object %}
{% set workflow_instance.document.metadata_value_of.Document_End_Date|split:“/” as end_date_list %}
{% set end_date_list.1|add:“/”|add:end_date_list.0|add:“/”|add:end_date_list.2|date_parse as doc_enddate_object %}
{% set now_date_object|date:“U” as nowsec %}
{% set doc_enddate_object|date:“U” as endsec %}
{% set doc_end_date_object|sub:now_date_object|join:“” as time_diff %}
{% if endsec|sub:nowsec|div:86400 <= 30 %}
Yes
{% endif %}
{% endspaceless_plus %}

9- I’ve added two escalations to the check state to transition the document either to the active state or to the expired state as per a condition (with a priority 0 for the active state):

My tests are good till now and its working as expected.

Note: I’m checking for another scenario too, to use an external workflow engine to do the heavy lifting (utilising the http request action in mayan workflow), I’m using n8n and its promising too,
I’m using local llama and n8n to summarise documents (especially contracts), formulate and humanise reminder mails, still trying with image processing though (but this can add a lot to the mix).

Sorry again, and hope this helps