Ad hoc Approval with Email Template

Here is a variation of the Ad hoc Approval workflow where we set up some Email Templates to use in sending emails to the participants in the workflow.

See the Ad hoc Approval Workflow article for a basic understanding of how this workflow model works.

Here is the modified workflow model that we'll use:

{
    "id": "sample:adhoc",
    "title": "Sample Adhoc Approval (with Email Template)",
    "nodes": {
        "start": {
            "type": "start",
            "transitions": {
                "start": "step1"
            }
        },
        "step1": {
            "type": "participant",
            "title": "Please approve the attached documents",
            "description": "The provided documents require your approval",
            "swimlane": "approver",
            "transitions": {
                "approve": "approve",
                "reject": "reject"
            },
            "handlers": {
                "ENTER": [{
                    "type": "email",
                    "config": {
                        "subject": "Please approve the attached documents",
                        "templateKey": "waiting_approval"
                    }
                }]
            }            
        },
        "approve": {
            "type": "passthru",
            "transitions": {
                "end": "end"
            }
        },
        "reject": {
            "type": "passthru",
            "transitions": {
                "end": "end"
            }
        },
        "end": {
            "type": "end"
        }
    },
    "swimlanes": {
        "approver": {
            "principals": []
        }
    }
}

We also add an Email Template (of type n:email_template). The key for the Email Template is waiting_approval (which matches what we reference in our Workflow Model).

The Email Template might look like this:

<p>
    Hello {{workflowTask.assigneeName}}, the following documents are awaiting your approval:
</p>
<ul>
    {{#each workflowTask.documents}}
    <li>
        <a title="{{data.title}}" href="{{@root.workflowTask.url}}/documents/{{id}}">
        {{data.title}}
        </a>
    </li>
    {{/each}}
</ul>

Suppose we now create a document that we'll launch this workflow against. The document might look like:

{
    "title": "Ricky Vaughn to Come out of Retirement, Pitch for Cleveland Indians",
    "url": "https://www.mlb.com/indians",
    "body": "The Indians got a bit of surprising news this morning when former Indians ace Ricky "Wild Thing" Vaughn announced that he was planning a comeback to Major League Baseball. It was welcome news to a pitching staff that was a combined 69-93 with a 4.30 ERA in 2010."
}

(credits to Bleacher Report for the satire)

Let's now Start the Workflow. When we do, an email will be send to the approver. The email will be generated using the Email Template we provided. And the Email Template will produce something like the following:

Hello joesmith, the following documents are awaiting your approval:

- Ricky Vaughn to Come out of Retirement, Pitch for Cleveland Indians

Where the bullet item is a link to a URL that is something like this:

https://subdomain.cloudcms.net/#/projects/771dc3ccc6281f1de5e8/tasks/c26652acdf44afd3df07/documents/967629c193a5f6f58483

When the email is received by the approver, they will be able to click this link to jump right into Cloud CMS and approve the document. This is a link to the Workflow Task management screen. This screen lets the approver inspect the document for approval, add comments, view workflow history and make decisions about whether to approve or reject the workflow.