Send Periodic Expiration Email Notifications in Office 365 and SharePoint 2013 Workflows

Introduction

In this article, I want to cover the very common scenario in any business system, alert notifications or a reporting subsystem. Usually that function has the responsibility of notifying end users about new events, overdue tasks and sending summary reports via e-mail. I want to review a couple of simple cases that I hope you can manually customize and implement in your environment. All the cases I created use SharePoint Online with an installed Plumsail Workflow Actions Pack, but you can implement it in an OnPremise environment as well.

Personal Item/Task/Document expiration reminders

The first case that I want to describe has a very simple simple goal, that is for a user to be able to track the status of sent items, tasks or documents. It could be an application form for a business trip, day-off request, assigned task or something else. It depends on your business process, but the core idea is the same. You have an item with a specific due date and a person responsible for this item. You need to send a notification message to the user when the due date arrives and of course you can customize the message template. Using SharePoint Designer you can create a site-level workflow that will select all list items by specific query and process each item. As an example, it could generate an email by template and send it.

Out-of-the-box workflow actions don't allow the querying of list items by CAML or generation of email messages by templates. That is why I used some workflow actions from the Workflow Actions Pack to extend the out-of-the-box functionality.

The following shows the configured workflow:



Figure 1: Reminder Workflow

I used the following CAML query to get all the list items that expire in two days in the Get Items by query workflow action:

  1. <View>  
  2.     <ViewFields>  
  3.         <FieldRef Name='ID' />  
  4.         <FieldRef Name='Title' />  
  5.         <FieldRef Name='DueDate' />  
  6.         <FieldRef Name='AssignedTo' />  
  7.     </ViewFields>  
  8.     <Where>  
  9.         <And>  
  10.             <Neq>  
  11.                 <FieldRef Name='Status' />  
  12.                 <Value Type='Choice'>Completed</Value>  
  13.             </Neq>  
  14.             <Lt>  
  15.                 <FieldRef Name='DueDate' />  
  16.                 <Value Type='DateTime'>  
  17.                     <Today OffsetDays='2' />  
  18.                 </Value>  
  19.             </Lt>  
  20.         </And>  
  21.     </Where>  
  22. </View>  

The following is the send email workflow action configuration (to simplify the process I designed the email template inside):

  1. Hello [%Variable: userField%] <br /><br /> Have you had time to look into this? <br /><br />  
  2.   
  3. <a href=”http://demo.plumsail.com/sites/NotificationCase/Lists/Workflow Tasks/DispForm.aspx?ID=[%Variable:ListItemID%]”>      [%Variable:ListItemTitle%]</a><br />  
  4. The Due Date is [%Variable: DueDate%]  
  5.   
  6. <br /><br />  
  7. Kind Regards, <br />  
  8.   
  9. SharePoint Notification System  

You can see the sceenshot below as the result:



Figure 2: Result Email

Daily/Weekly/Mounthly aggregated expiration reports by email

The second example that I want to show is based on the same algorithm, but you need to get an aggregated summary report instead of sending notifications to each user. To do this you can get all the data and use a Render Template workflow action to build the complete email by predefined template.

In the following I implemented the workflow for a typical case of when an administrator wants to get a summary report with a list of all checked-out documents ordered by a user.

In the figure below you can see the configured workflow, I split it into two stages to simplify the configuration and copying to other document libraries.



Figure 3: Workflow

The first step is just the configuration section.

Next, I got all list items where the field CheckoutUser is not null, I used the following CAML query for this:

  1. <View Scope="RecursiveAll">  
  2.     <ViewFields>  
  3.         <FieldRef Name="CheckoutUser"/>  
  4.         <FieldRef Name="FileRef"/>  
  5.         <FieldRef Name="FileLeafRef"/>  
  6.     </ViewFields>  
  7.     <Query>  
  8.         <Where>  
  9.             <IsNotNull>  
  10.                 <FieldRef Name="CheckoutUser"/>  
  11.             </IsNotNull>  
  12.         </Where>  
  13.         <OrderBy>  
  14.             <FieldRef Name="CheckoutUser"/>  
  15.             <FieldRef Name="FileLeafRef"/>  
  16.         </OrderBy>  
  17.     </Query>  
  18. </View>  

Then I prepared the data for the Render Text Template workflow action. I used the following template:

  1. Please review the list of documents which was checked out:   
  2. <br />  
  3. <br />  
  4. <table>  
  5.     <thead>  
  6.         <td>  
  7.             <strong>User Name</strong>  
  8.         </td>  
  9.         <td>  
  10.             <strong>Document</strong>  
  11.         </td>  
  12.     </thead>  
  13.     <tbody>  
  14. {{#each Documents}}  
  15.   
  16.         <tr>  
  17.             <td>{{FieldValues.CheckoutUser}}</td>  
  18.             <td>  
  19.                 <a href="{{SiteUrl}}{{FieldValues.FileRef}}">{{FieldValues.FileLeafRef}}</a>  
  20.             </td>  
  21.         </tr>  
  22. {{/each}}  
  23.   
  24.     </tbody>  
  25. </table>  
  26. <br />  
  27. <br />  
  28.   
  29. Thank you,   
  30. <br />  
  31. SharePoint Notification System.   
  32. <br /> 

Before sending the message I used a Regular Expression Replace workflow action to replace values in the User's field from the value like 24#;John Martin to 24 - John Martin.

And at the final step I sent a complete email report to an administrator as in the following:



Figure 4: Result Email

Conclusion

In this article I wanted to describe some common cases that can be used for alerting or reminding purposes. I hope it was clear enough and it will not be difficult to repeat it or customize to your own requirements. Please feel free to comment on the article.

Origianl posted at How to send periodic expiration email notifications in Office 365 and SharePoint 2013 Workflows.