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:
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.


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.