Using the capabilities of sending e-mail and processing incoming e-mail in workflows
This example will show you how to use actions from HarePoint Workflow Extensions set for working with E-mail. We will look at sending of messages and processing of incoming messages.
Let's consider this situation as an example: a task list has been created on a SharePoint site. When creating a task, the employee responsible for it is chosen. However, the employee may be outside the office with no access to the corporate network. Therefore, the task is:
To do this, we will create two workflows. The first one, when a new list item is created, will send a message with a notification and item contents to the employee responsible for the task from a certain mail box. The employee can then simply respond to the message (the responce will come to the mailbox from which the first workflow sent the notification). The second workflow will parse the user's answer and mark the task as approved or rejected.
To create these workflows, we will use both standard SharePoint actions and actions from the HarePoint Workflow Extensions set. The list of the used items:
Before starting the creation of workflows
The first workflow. Sending a notification
This workflow will be automatically launched when a new item in the task list is created.
The purpose of this workflow is to send a notification.
Let's start the creation
1. Create List Workflow.
2. Create a variable, “Item Url”
3. Using the action, “Get List Item Url”, save the task page address to the created variable on the SharePoint portal.
4. Using the “Send E-Mail without Attachments” action, send the message to the responsible employee.
The content of variable “Item Url” is used as the address of the hyperlink to the task page:
The first workflow is ready. Here is what the ready workflow looks like:
Save and publish the workflow.
When adding a new task to the list, a message will be automatically sent to the responsible employee:
The second workflow. Parsing responses to notifications
This workflow will be automatically launched when a new item in the list of responses to notifications is created, i.e. when a new message is received.
The purpose of this workflow is to receive an answer to a notification and change the status of the task list item.
Procedure of the workflow operations
The procedure can be split into three main stages:
1. Create List Workflow
2. Obtain reference to the task list item
You can use regular expressions in the first parameter of this action. To obtain MAPPID the following regular expression was used:
Using the action, “Extract Substring” extract the item identifier (GUID) from the obtained string:
Using the action “Find List Item” find all list items with the identifier just obtained:
To obtain the Url of the list in which the search is conducted, you can use the action, “Get List Url”, or simply copy this Url from the browser address string. In the case considered in the example, the browser string for the list’s address is: http://sp14.vlab.mapilab.local:133/Lists/HarePoint%20Tasks/AllItems.aspx
The whole string including the last slash is needed: http://sp14.vlab.mapilab.local:133/Lists/HarePoint%20Tasks/
Using the action, “Get Array Items Count”, obtain the number of items found. Since we are searching by the identifier, there should be only one search result. Check this using the condition, If any value equals value:
If this condition is met, then an error occurred. The workflow failed to find the item, for example, because it has been removed, or because the message sender has changed the identifier. In this case, it is necessary to stop the workflow and make a record in the log as to why it was stopped:
If the condition was not met, everything continues. Save the reference to the item found in the variable:
The first stage is completed.
3. Check whether the message sender is responsible for this task
Using the action “Get Field Value at Url” obtain the person to whom the task is assigned:
Using the same action obtain the message author from the item of the answer list:
Compare whether it is the same person using the condition “If any value equals value”:
And if the condition is met (these are different people), stop the workflow retaining information for debugging and investigations in the log:
If the condition was not met, everything continues to the third stage.
4. Check whether the message (the first 30 symbols) contains key words, change the status of the task list item.
Using the action, “Trim Text”, remove redundant spaces from the text beginning and ending:
Using the action, “Extract Substring from Start of String”, obtain the first 30 symbols from the message:
All these actions are required to separate the text of the task itself from the text checked for key words.
Using action “Capture Text” find key words in the message.
Attention: to make a regular expression work, the response to the notification must start with a key word, because it is included in the data condition of regular expressions (“^” – the symbol of string beginning).
If the message has approving key words:
Approve the task using the action, “Approve Item at Url”, and add a record to the log.
If there are no approving key words, but there are rejecting ones:
Use the action, “Reject Item at Url,” and add a record to the log.
If the message does not have either approving or rejecting key words, we simply write the record about it to the log:
The second workflow is ready. The ready workflow looks like this:
Save and publish the workflow.
Now the answer to the notification will be processed by this workflow:
Email plays a significant role in SharePoint operation. Using additional actions and conditions from HarePoint Workflow Extensions optimizes the email handling capabilities of SharePoint. You can automate many actions by parsing incoming messages that otherwise would have to be done manually. Furthermore, you can build a system of notifications concerning any events with documents or list items.