{"id":237,"date":"2012-04-21T14:23:38","date_gmt":"2012-04-21T14:23:38","guid":{"rendered":"https:\/\/www.harepoint.com\/Blog\/?p=237"},"modified":"2020-04-06T12:54:32","modified_gmt":"2020-04-06T12:54:32","slug":"workflow-approval-by-e-mail-in-sharepoint","status":"publish","type":"post","link":"https:\/\/www.harepoint.com\/Blog\/workflow-approval-by-e-mail-in-sharepoint\/","title":{"rendered":"Workflow approval by e-mail in SharePoint"},"content":{"rendered":"\n<ul>\n<li><a href=\"#email_workflow\">Perform operations with e-mails in SharePoint workflows<\/a>\n<li><a href=\"#preparing\">Get ready to start workflows creation<\/a>\n<li><a href=\"#workflow1\">Workflow #1 &#8211; Sending notification<\/a>\n<li><a href=\"#workflow2\">Workflow #2 &#8211; Parsing responses to notifications<\/a>\n<li><a href=\"#conclusion\">Conclusions<\/a>\n<\/ul>\n\n<p><i>Updated at April 6, 2020<\/i><\/p>\n\n<a name=\"email_workflow\"><\/a>\n<h2>Using the capabilities of sending e-mail and processing incoming e-mail in workflows<\/h2>\n<p>This example will show you how to use actions from <a href=\"https:\/\/www.harepoint.com\/Products\/HarePointWorkflowExtensions\/Default.aspx\"><b>HarePoint Workflow Extensions for SharePoint<\/b><\/a> set for working with Email. We will look at sending of messages and processing of incoming messages.<\/p>\n<p>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:<\/p>\n<ul>\n<li>To inform the employee about the task assigned via e-mail.<\/li>\n<li>To give the employee the opportunity to accept or to reject the task using an operation simple for him, for example, by simply replying to the message.<\/li>\n<\/ul>\n<p>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 mailbox. The employee can then simply respond to the message (the response 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.<\/p>\n<p>To create these workflows, we will use both standard SharePoint actions and actions from the <b>HarePoint Workflow Extensions<\/b> set. The list of the used items:<\/p>\n\n<table border=\"1\" cellpadding=\"5\" style=\"border-style: solid; border-collapse: collapse; border-spacing: 0px;\"><tbody><tr><td rowspan=\"2\"><b>Component name and type<\/b><\/td>\n<td align=\"center\" colspan=\"2\"><b>Set of Workflow components<\/b><\/td><\/tr>\n<tr><td align=\"center\"><b>SharePoint Workflow<\/b><\/td>\n<td align=\"center\"><b><a href=\"https:\/\/www.harepoint.com\/Products\/HarePointWorkflowExtensions\/ListActivities.aspx\">HarePoint Workflow Extensions<\/a><\/b><\/td><\/tr>\n\n<tr><td>Get List Item Url<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Send E-Mail without Attachments<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Capture Text<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Extract Substring<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Find List Item at Url<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Get Array Items Count<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>If any value equals value<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td>\n<td><\/td>\n<\/tr>\n\n<tr><td>Stop Workflow<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td>\n<td><\/td>\n<\/tr>\n\n<tr><td>Get Array Item<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Get Field Value at Url<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Log to History List<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td>\n<td><\/td>\n<\/tr>\n\n<tr><td>Convert HTML To Text<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Trim Text<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Extract Substring from Start of String<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td>\n<td><\/td>\n<\/tr>\n\n<tr><td>Approve Item at Url<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<tr><td>Reject Item at Url<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\"\/><\/td><\/tr>\n\n<\/tbody><\/table>\n\n<a name=\"preparing\"><\/a>\n<h2>Before starting the creation of workflows<\/h2>\n<ul>\n<li><i>Create a task list<\/i><br\/>\nCreate a list of the \u201cTasks\u201d type on the SharePoint site. For example, let\u2019s name this list \u201cHarePoint Tasks\u201d.<\/li>\n<li><i>Turn on the requirement for approving items in the task list<\/i><br\/>\nThe instructions for turning on approval for items are on the Microsoft site.<\/li>\n<li><i>Create a list for receiving answers to notifications and configure the E-Mail support<\/i><br\/>\nYou can watch the catalogue of lists for which the receipt of incoming e-mail is available and the instruction for configuring the incoming e-mail on the Microsoft site. Let\u2019s take a list of the \u201cAnnouncements\u201d type as an example and name it \u201cMailApproval\u201d. Specify the incoming address for this list in the list settings \u2014 mailapproval@sp14mail.vlab.mapilab.local\n<\/li>\n<\/ul>\n\n<a name=\"workflow1\"><\/a>\n<h2>The first workflow. Sending a notification<\/h2>\n\n<p>This workflow will be automatically launched when a new item in the task list is created.<\/p>\n<p>The purpose of this workflow is to send a notification.<\/p>\n<p><b>Procedure<\/b><\/p>\n<ul>\n<li>Obtain the Url of the task page on the SharePoint portal<br\/><\/li>\n<li>Send a notification with the task reference and identifier via E-Mail<br\/>\nIt is very important to specify the sender\u2019s address.<\/li>\n<\/ul>\n\n<p><b>Let&#8217;s start the creation<\/b><\/p>\n\n<p><i>1. Create List Workflow.<\/i><br\/>\nSpecify the name of the task list at the creation (\u201cHarePoint Tasks\u201d). In the workflow start options, mark the checkbox \u201cStart workflow automatically when an item is created\u201d:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-01.PNG\"\/><\/p>\n<p><i>2. Create a variable, \u201cItem Url\u201d <\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-02.PNG\"\/><\/p>\n<p><i>3. Using the action, <b>\u201cGet List Item Url\u201d<\/b>, save the task page address to the created variable on the SharePoint portal.<\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-03.PNG\"\/><\/p>\n<p><i>4. Using the <b>\u201cSend E-Mail without Attachments\u201d<\/b> action, send the message to the responsible employee.<\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-04.PNG\"\/><\/p>\n<p>The content of variable \u201cItem Url\u201d is used as the address of the hyperlink to the task page:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-05.PNG\"\/><\/p>\n<p><b>Pay attention:<\/b><\/p>\n<ul><li>The message text itself can be made in any suitable manner according to your goals, the style of your correspondence, or personal preferences. From the technical point of view, the most important is the last string of the message, which the second workflow (which parses responses to notifications) will use to find the item in the task list and mark it as approved or rejected.<\/li>\n<li>It is very important to specify the E-Mail address from which a notification will be send. This is the address to which responses from employees will come.<\/li>\n<\/ul>\n<p>The first workflow is ready. Here is what the ready workflow looks like:<\/p>\n<p><a href=\"\/Pictures\/Workflow\/Example-Lazy-Approval-06.PNG\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-06.PNG\"\/><\/a><\/p>\n\n<p>Save and publish the workflow.<\/p>\n<p>When adding a new task to the list, a message will be automatically sent to the responsible employee:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-07.PNG\"\/><\/p>\n\n<a name=\"workflow2\"><\/a>\n<h2>The second workflow. Parsing responses to notifications<\/h2>\n<p>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.<\/p>\n<p>The purpose of this workflow is to receive an answer to a notification and change the status of the task list item.<\/p>\n<p><b>Procedure of the workflow operations<\/b><\/p>\n<p>The procedure can be split into three main stages:<\/p>\n<ol>\n<li>Receive the reference to a task list item<\/li>\n<li>Check whether the message sender is responsible for this task<\/li>\n<li>Check whether the message (first 30 symbols) contains key words, change the status of the task list item<\/li>\n<\/ol>\n\n<b>Let\u2019s create the workflow<\/b><p><i>1. Create List Workflow<\/i>\n<br\/>Specify the name of the task list at the creation (\u201cMailApproval\u201d). Mark the checkbox \u201cStart workflow automatically when an item is created\u201d in the workflow start options:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-01.PNG\"\/><\/p>\n<p><i>2. Obtain reference to the task list item<\/i>\n<br\/>Use the <b>action \u201cCapture Text\u201d<\/b> MAPPID from the message body:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-08.PNG\"\/><\/p>\n<p>You can use regular expressions in the first parameter of this action. To obtain MAPPID the following regular expression was used:<\/p>\n<ul><li>(?:MAPPID=)(\\x7B[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\\x7D)<\/li><\/ul>\n<p>Using the <b>action, \u201cExtract Substring\u201d<\/b> extract the item identifier (GUID) from the obtained string:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-09.PNG\"\/><\/p>\n<p>Using the <b>action \u201cFind List Item\u201d<\/b> find all list items with the identifier just obtained:<\/p>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-10.PNG\"\/><\/p>\n\n<p>To obtain the Url of the list in which the search is conducted, you can use the action, <b>\u201cGet List Url\u201d<\/b>, or simply copy this Url from the browser address string. In the case considered in the example, the browser string for the list\u2019s address is: http:\/\/sp14.vlab.mapilab.local:133\/Lists\/HarePoint%20Tasks\/AllItems.aspx<\/p>\n\n<p>The whole string including the last slash is needed: http:\/\/sp14.vlab.mapilab.local:133\/Lists\/HarePoint%20Tasks\/<\/p>\n\n<p>Using the action, <b>\u201cGet Array Items Count\u201d<\/b>, 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:<\/p>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-11.PNG\"\/><\/p>\n\n<p>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:<\/p>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-12.PNG\"\/><\/p>\n<p>If the condition was not met, everything continues. Save the reference to the item found in the variable:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-13.PNG\"\/><\/p>\n<p>The first stage is completed.<\/p>\n<p><i>3. Check whether the message sender is responsible for this task<\/i>\n<br\/>Only employee responsible for the task should be able to change the task status.<\/p>\n<p>Using the action <b>\u201cGet Field Value at Url\u201d<\/b> obtain the person to whom the task is assigned:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-14.PNG\"\/><\/p>\n<p>Using the same action obtain the message author from the item of the answer list:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-15.PNG\"\/><\/p>\n<p>Compare whether it is the same person using the condition \u201cIf any value equals value\u201d:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-16.PNG\"\/><\/p>\n<p>And if the condition is met (these are different people), stop the workflow retaining information for debugging and investigations in the log:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-17.PNG\"\/><\/p>\n<p>If the condition was not met, everything continues to the third stage.<\/p>\n<p><i>4. Check whether the message (the first 30 symbols) contains key words, change the status of the task list item.<\/i>\n<br\/>Using the <b>action, \u201cConvert HTML To Text\u201d<\/b>, we retain only text in the message body:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-18.PNG\"\/><\/p>\n<p>Using the <b>action, \u201cTrim Text\u201d,<\/b> remove redundant spaces from the text beginning and ending:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-19.PNG\"\/><\/p>\n<p>Using the <b>action, \u201cExtract Substring from Start of String\u201d,<\/b> obtain the first 30 symbols from the message:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-20.PNG\"\/><\/p>\n<p>All these actions are required to separate the text of the task itself from the text checked for key words.<\/p>\n<p>Using <b>action \u201cCapture Text\u201d<\/b> find key words in the message.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-21.PNG\"\/><\/p>\n<p>Regular expressions:<\/p>\n<ul>\n<li>For approving key words: ^(?:yes|approve|ok|agree)[\\p{P}\\s\\r\\n]+<\/li>\n<li>For rejecting key words: ^(?:no|reject|cancel)[\\p{P}\\s\\r\\n]+<\/li>\n<\/ul>\n<p><b>Attention:<\/b> 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 (\u201c^\u201d \u2013 the symbol of string beginning).<\/p>\n<p>If the message has approving key words:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-22.PNG\"\/><\/p>\n<p>Approve the task using the <b>action, \u201cApprove Item at Url\u201d,<\/b> and add a record to the log.<\/p>\n<p>If there are no approving key words, but there are rejecting ones:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-23.PNG\"\/><\/p>\n<p>Use the <b>action, \u201cReject Item at Url,\u201d<\/b> and add a record to the log.<\/p>\n<p>If the message does not have either approving or rejecting key words, we simply write the record about it to the log:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-24.PNG\"\/><\/p>\n<p>The second workflow is ready. The ready workflow looks like this:<\/p>\n\n<p><a href=\"\/Pictures\/Workflow\/Example-Lazy-Approval-25.PNG\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-25.PNG\"\/><\/a><\/p>\n<p><a href=\"\/Pictures\/Workflow\/Example-Lazy-Approval-26.PNG\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-26.PNG\"\/><\/a><\/p>\n<p>Save and publish the workflow.<\/p>\n<p>Now the answer to the notification will be processed by this workflow:<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-Lazy-Approval-27.PNG\"\/><\/p>\n\n<a name=\"conclusion\"><\/a>\n<h2>Conclusions<\/h2>\n<p>Email plays a significant role in SharePoint operation. Using <a href=\"\/Products\/HarePointWorkflowExtensions\/Default.aspx\">additional actions and conditions from HarePoint Workflow Extensions<\/a> 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.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example will show you how to use the capabilities of actions from the HarePoint Workflow Extensions set for working with E-Mail. We will consider sending of messages and processing of incoming messages.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[15,14,25],"_links":{"self":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":7,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":1671,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/1671"}],"wp:attachment":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}