Tutorial: Weekly Document Count Alert

This tutorial builds a scheduled Automation that emails you once a week — but only when your document count has climbed to within 10% of a limit you set. The example uses a limit of 50,000 documents, so the email goes out only when the count reaches 45,000 or more. Below that the Automation runs, checks, finds nothing to report, and stays quiet.


It takes three pieces: a Custom Variable holding the limit, an Action Set that does the math and sends the email, and an Automation that runs the Action Set on a schedule.


The variables you will use

DocMgt exposes system-wide Record and Document counts through the [USAGE()] variable. It takes one value that tells it what to return.


Variable

Returns

[USAGE(DOC)]

All documents — active plus everything sitting in the Recycle Bin

[USAGE(DOCA)]

Active documents only

[USAGE(DOCD)]

Documents in the Recycle Bin only

[USAGE(REC)]

All records — active plus Recycle Bin

[USAGE(RECA)]

Active records only

[USAGE(RECD)]

Records in the Recycle Bin only

[USAGE()]

All six counts at once, as a block of JSON


Which one you should watch depends on how your storage is counted for you. If deleted documents still occupy space until they are purged, watch [USAGE(DOC)]. If only live documents matter, watch [USAGE(DOCA)]. This tutorial uses [USAGE(DOC)].


Three general-purpose variables do the arithmetic. [MATH()] performs a calculation, so [MATH(50000*0.9)] produces 45000. [ROUND()] trims decimal places, as in [ROUND(value|1)]. [FORMAT()] applies a display format, so [FORMAT([USAGE(DOC)]|#,##0)] turns 45213 into 45,213 for the email body.


Step 1 — Put the limit in a Custom Variable

You could type 50000 straight into the Action Set, but then the number lives in three or four places and you have to remember all of them when the limit changes. Define it once instead. Go to Admin > Automation > Custom Variables and add a new one.


Set Name to DOCLIMIT — enter it without the brackets; you use it as [DOCLIMIT] everywhere else. Set Short Description to something like "Licensed document limit". Turn Show in List on so it appears in variable pickers. Leave Parameters empty. Set Variable Code to 50000.


From now on [DOCLIMIT] returns 50000 anywhere variables are honored, and when your limit changes you edit this one record.


Step 2 — Build the Action Set

Go to Admin > Automation > Action Sets and create one named Document Count Alert. Add a single Send Email action to it. Fill in the recipient, then write the subject and body using the variables — the calculations happen right there in the text.


For the subject: Document storage at [ROUND([MATH([USAGE(DOC)]*100/[DOCLIMIT])]|1)]% of limit


For the body:


Weekly document storage check for [SERVERURL].


Documents stored:  [FORMAT([USAGE(DOC)]|#,##0)]

   Active:         [FORMAT([USAGE(DOCA)]|#,##0)]

   Recycle Bin:    [FORMAT([USAGE(DOCD)]|#,##0)]

Records stored:    [FORMAT([USAGE(REC)]|#,##0)]


Limit:             [FORMAT([DOCLIMIT]|#,##0)]

Remaining:         [FORMAT([MATH([DOCLIMIT]-[USAGE(DOC)])]|#,##0)]

Percent used:      [ROUND([MATH([USAGE(DOC)]*100/[DOCLIMIT])]|1)]%


You are receiving this because usage has reached 90% or more of the limit.


Step 3 — Add the 90% condition

The Action Set runs every week no matter what. What keeps the email from going out every week is a filter on the action itself.


On the Send Email action, add a filter of type Value Comparison and fill in its three parts. Put [USAGE(DOC)] in the Value to Check box. Choose Is Greater Than or Equal To as the comparison. Put [MATH([DOCLIMIT]*0.9)] in the Value box.


DocMgt resolves the variables on both sides first, then compares the two as numbers. On a Monday morning with 42,300 documents stored it compares 42300 against 45000, the filter fails, and the action is skipped. When the count crosses 45,000 the filter passes and the email goes out. It keeps going out every Monday until you raise the limit or clear out documents, which is what you want from a storage warning.

The Value Comparison rule is literal, which means it does not support the # and !# shortcuts that some other rules accept. Plain values and variables are all it works with — which is exactly what this filter uses.


Step 4 — Schedule it as an Automation

Automations live on Record Types, but a scheduled Automation does not operate on the records in that Record Type — it runs globally. The Record Type is only where the schedule is parked, so any Record Type will do. Pick one you will remember, or a quiet one you rarely touch.


Open Admin > Record Types, edit that Record Type, and expand the Automation section. Below the Retention list you will find the Automation list. Click Add Automation and fill in four things.

Set Description to Weekly Document Count Alert. Turn Enabled on. Choose Document Count Alert in the Action Set dropdown. For Schedule, choose Weekly, pick MON, and pick the hour you want — 7 for 7:00 AM, which builds the expression 0 0 7 ? * MON *. Leave Time Zone set to SERVER so the email arrives at 7:00 AM local time rather than 7:00 AM UTC.


Click OK and save the Record Type. That is the whole thing — no record to create, no workflow to start.


What the Action Set can and cannot see

Because the Automation runs globally, there is no record and no document in context when the Action Set runs. System and calculation variables like [USAGE()], [MATH()], [DATE] and [SERVERURL] all work normally. Record variables such as [RECORDID] and [Field Name] have nothing to read and come back empty, so keep them out of these actions.


Adjusting the recipe

  • To change the limit, edit the DOCLIMIT Custom Variable. The subject line, the body, the remaining count, and the threshold all recalculate from it.


  • To change the warning point from 90% to some other figure, edit the 0.9 in the Value Comparison filter — 0.8 warns at 80%, 0.95 warns at 95%. If you would rather not hunt for it later, make a second Custom Variable named DOCWARNPCT with a Variable Code of 0.9 and use [MATH([DOCLIMIT]*[DOCWARNPCT])] in the filter instead.


  • To watch record counts rather than document counts, swap [USAGE(DOC)] for [USAGE(REC)] throughout, including inside the filter.


  • To send daily instead of weekly, choose Daily in the Schedule picker rather than Weekly.


  • To add a second, louder warning at 100%, add another Send Email action to the same Action Set with its own Value Comparison filter checking [USAGE(DOC)] Is Greater Than or Equal To [DOCLIMIT]. Both actions run on the same weekly schedule and each decides for itself whether to fire.


TIPS

  1. Test the threshold before you trust it. Temporarily set DOCLIMIT to a number just above your current count — the next run should send the email — then set it back to the real limit.
  2. Send the alert to a distribution list rather than one person. A storage warning that lands in the inbox of someone on vacation is a warning nobody acts on.
  3. If you want a reading you can check any time rather than waiting for Monday, put the same [USAGE(DOC)] variables on an E-form and open it whenever you like.