Create a Detailed Custom Task Notification with a SharePoint Designer Workflow

Update June 6, 2012: If you would like to know how to do this in SharePoint 2010, click here for a video tutorial.

It seems that few SharePoint users are happy with the out-of-the box task notifications. While they serve their purpose, we often want highly customized emails that contain more information about the task.

I recently created a workflow that used the Collect Data from a User activity. When you go through the Custom Task Wizard, SharePoint Designer creates a Content Type (based on the parameters you selected) in your site and adds that content type to the Workflow Tasks list for the site. The task notifications use the standard template though and look like this:
image

So, in this example, Alan needs to correct something in inventory. He can see that an item called “Shipped to Dan’s Bikes” created the task, but he really doesn’t have any idea what he needs to correct, or why he needs to correct it. He could probably figure it out if he clicked on the link to Shipped to Dan’s Bikes, but that’s not very intuitive and still means more work for Alan. If he clicks on the link to Edit this task, he doesn’t get much more details there:
image

Alan would like to receive an email with all the details he needs and a link to this form to enter his count.

We’ll need to do a few things to replace SharePoint’s default notification with our own. The first thing we need to do is turn off SharePoint’s default notification. On the Workflow Tasks list, go the Advanced Settings and select No for Send e-mail when ownership is assigned.
image

Next, you’ll need to launch SharePoint Designer, open the site, and create a new workflow.Attach the workflow to your Tasks list and select the option to run when a new item is created.

It’s possible that your Tasks list could contain multiple types of content types, so you’ll want to add conditions in your workflow for each Content Type or create separate workflows for each Content Type. My Content Type was called Inventory Correction, so I check for that in my first condition:
image

I want my email notification to contain some details about the task and be less generic than the out of the box notifications. You’ll remember that notification just said, “Tasks – Inventory Correction Has Been Assigned To You.” I would like it to say, “New Task: Correct Inventory for the Appalachian Mountain Bike” so that the recipient had a better idea of what he had to do. So, the first action I added to my workflow was Build a Dynamic String. In the String Builder, I typed in the my static text and added a Lookup to get the name of the bicycle from the list item on which the workflow was running that created the task. To find this I matched the Current Item: Workflow Item ID with the ID of the item in the Inventory Adjustments list (that is the list that triggered this task to be created). The lookup looked like this:
image

And the Dynamic String looked like this:
image
I stored that string in a variable named New Task Title. 

So, another important lesson here is that the Workflow Item ID always matches the ID of the item on which the workflow was running that created the task, so it can be used to get to any of that information. Sweet!

Next, I added an action to my workflow to Send and Email. In the Define E-mail Message dialog, I set the subject line to be the Dynamic String I just created.

I also wanted a link directly to the form to edit the task. So, I opened up an existing task and copied the URL for it from my address bar. I added some HTML anchor tags to my email and pasted this URL in as the HREF. I also needed to Look Up to change the ID for the task.

In the body of the email, I used the Workflow Item ID to do lookups on the Inventory Adjustments list to dynamically populate the Bicycle Type, who created the adjustment that caused the problem, and the original adjustment amount. Here is what my completed dialog looked like.

image

Finally, I wanted to change the Title of the task in the task list to provide more information. I used the Set Field in Current Item activity to change the Title to be the same thing as the subject line of the email. Here is what the complete workflow looked like:
image

When this workflow runs, it changes the Title of the task from the default “Inventory Correction” (which is the name of the Content Type) to “New Task: Correct Inventory for the Appalachian Mountain Bike.”image

And the Warehouse Manager gets an email with a link to the edit task page and all the details about why he needs to make the correction:image

If you want to learn more about how to take you SharePoint Designer workflows to the next level, be sure to sign up for our Mission: Automation – SharePoint Workflow and InfoPath class! Hopefully I’ll see you there!

14 Comments

  1. Avatar of Eric Fuhriman

    Eric Fuhriman - February 15, 2011, 12:55 pm

    Thank you for this post! – This is exactly what I was looking for. I have one issue that I am runing into though and am having a tough time solving it (if it is possible). I have a workflow that sends a collect data task to a supervisor. Using your approach and customizing the email with links to the task works great! Once the supervisor approves, then it sends a collect data task to information owners who need to review the request and approve or deny the request. But when this task is created the link send the information Owner to the Supervisor data collect task that has already been complete and not to the information owner collect data task. I take it that I have an issue tieing the Task ID to the specific collect data request. Any ideas on what I am doing wrong?

  2. Avatar of Ricky Spears

    Ricky Spears - February 15, 2011, 6:19 pm

    efuhriman – This is difficult to diagnose just from the information you’ve provided. I’ll try it with my best understanding though. I assume that you’ve written a second workflow that only runs on the Content Type for the second Collect Data Task. The link there would be created just like this one, using the Current Item: Task ID.

    It get’s really tricky though if you want to update the Title or something using information from the item that triggered the overall workflow process. You’ll have to do a pretty complex lookup to get to that information because it will need to look up the Workflow Item ID from the previous task and then look that up on the original list. So, it should be something like this:
    Source: Inventory Adjustments
    Field: Bicycle Type
    Lookup Field: ID
    Value: [Click the formula button]
    Source: Tasks
    Field: Workflow Item ID
    Lookup Field: ID
    Value: [Click the formula button]
    Source: Current Item
    Value: Workflow Item ID

    Whew! I think I’ve got that right anyway. Hopefully you get the idea of the double lookup. If all else fails, we can do a web consultation and I (or one of our other consultants) will be glad to take a look at the issue with you and help you with it. Good luck!

  3. Avatar of Cory Booth

    Cory Booth - March 1, 2011, 8:55 am

    I am very interested in this workflow and need a bit more clarification if you can.
    My situation is I am trying to run a “Collect Data from User” task on a group of users I have established a variable for.
    From all my research, you cannot submit multiple users to the Collect Data from User task – only a Sharepoint Group or single user account.

    So, I decided I’d try to do this action using a method very similar to what you posted.

    The confusing part is:

    1. How do you obtain a Task:ID variable for the email notice if the task hasn’t been created yet?
    Looking at your steps, you build the Task Title, Email the users, and then update the Title. I don’t see where the actual “Task” was built in the Task List.

    For my case, I am trying to use a “Create List Item” action to build that “Task” and then pass the ID to a variable.
    This works, except when the task is wrote to the Task List, the “Link” column is blank.
    So I then tried to use a “Update List Item” or add a column to the “Create List Item” to pass the ID of the current item to the Task List to build that association.
    Unfortunately, the Link Column isn’t available to work with.

    2. Without a Task associated with the Item, how does the workflow know to “pause” and wait until the approval or whatever information is collected?
    Using my example above, if I write the task to the list and I send the email to my users, it all works, but the workflow doesn’t know to stop and wait – so it just keeps on moving.

    I’d really appreciate any insight you could provide on this situation…

    thank you very much!

  4. Avatar of Ricky Spears

    Ricky Spears - March 18, 2011, 11:25 am

    corybooth –

    1. The task was initially created by another workflow on another list using the Collect Data from a User activity.
    2. The Collect Data from a User activity does create a task, so there is no problem with the pause.

    So, having answered your questions, let’s take a look at how we can solve your business problem. :-) You want to use the Create List Item activity to create the task. My first thought is to create a column on the task list named something like “Creator Item ID”. When you set the fields in the new list item, set this field to be the same the “Current Item: ID” for the item that creates the task. This will allow you to easily look up the information you need from the item that created the tasks.

    The next thing is that you want the workflow that creates the new tasks via the “Create List Item” activity to pause until the task (or tasks) are complete. To accomplish this, I would add a column in the original list (the list that creates the task, not the task list) to track whether the task has been completed or not; let’s call it “Task Completed”. The workflow that runs on the task list can use the ‘Wait for Field Change in Current Item” to wait until the status is “Completed”. Then once the status column is set to completed, it can update the tracking column in the original list (“Task Completed”) that created the item. After you create the task in the original workflow using the Create List Item activity, use a Wait for Field Change in Current Item” activity to accomplish the pause you need.

    Hopefully that’s at least as clear as mud and will get you thinking in a new way. Good luck!

  5. Avatar of Rui Jiang

    Rui Jiang - April 19, 2011, 3:42 pm

    Hi Ricky – I’m so happy that I found your post, this is what I have been looking for. I wanted to update the task title including the title of the item in the orignal list.

    I have followed your post, created a workflow on the task list, built a Dynamic String, but somehow I could not retrive the title from the original list. I carefully read your response to efuhriman, still could not get anything. Can you explain the detailed steps for getting the title from the orginal list one more time?

    Thank you for your help,
    Rui

  6. Avatar of Ricky Spears

    Ricky Spears - May 23, 2011, 6:04 am

    Since SO MANY people want to do this, but are having so many problems following the steps here, I’m going to record a short screencast showing the steps so everyone will be able to watch that. It may make things more clear. I’ll do me best to record and publish that before the end of the week.

  7. SharePoint Help — Blog — Video: How to Create a Custom Task Notification with a SharePoint Designer 2010 Workflow - May 25, 2012, 3:49 pm

    [...] years ago I wrote a blog post about How to Create a Detailed Custom Task Notification with a SharePoint Designer Workflow. That blog post provided step-by-step instructions and screenshots for doing this in SharePoint [...]

  8. Avatar of Chris Heirene

    Chris Heirene - July 17, 2012, 7:23 am

    I was having the same problem as other people, namely how do you get it to send the email as the Collect Data… stage pauses the workflow and the task doesn’t exist prior to this. The solution which I am using and appears to work really well is to create a seperate workflow on the task list itself which handles renaming the task and sending out the email. All the steps above are the same (including stopping the default task list emailing) and you can utilise the Workflow Item ID on the task to get back to the original list item and from there you can then update the task to include the item name etc.

    This works fine on Sharepoint Foundation 2010.

  9. Avatar of Ricky Spears

    Ricky Spears - July 17, 2012, 1:25 pm

    chrisheirene – The entire process I’ve outlined here assumes that the workflow that creates the task is on the original list or library, and the workflow that sends the notificaiton email about the new task is written on the Tasks list.

  10. Avatar of John Foll

    John Foll - September 13, 2012, 4:52 pm

    I liked your solution. There is also another way to send a custom email for a Custom Task:

    Create a Parallel Task: Task 1) Collect Data From User, Task 2) Step -> Contains a Pause for 1 minute, then Email step.

    In the Email step you would have to lookup from the Associated Task looking up field by ID for the varible that stores the Collection Task ID in the workflow, if needed to get any of the task details. This would be needed to provide the URL HyperLink and the description of the task (TaskName or ContentType).

    This would be: In your email step body do: Edit Hyperlink. Put your Text to display like: “Click here to Approve or Reject this Form”, then on Address click on FX and pick Assoication: Task List, then Field from source: URL Path, then Find the list item: Field: ID, Value : DataSource=Workflow Variables and Parameters, Field from Source: Variable Collect, Return field as Item ID.

    This assumes that you stored your Collect Data from User task with Output to: Collect.

    This allows you to click on the hyperlink, which will display the form to approve or reject, etc.

    I tried this, and it failed, even after pausing for 2 minutes. The error I am getting is: “Coercion Failed: Input cannot be null for this coercion.”, which is happening in the parallel step which is trying to display the Associated: Task List : Task URL based on looking up the Associated Task list ID = my Collect TaskID from the CustomTask.

    I think its a timing issue or concurrency issue.

    I was able to do something like this in NinTex workflows, but no in the SharePoint workflows.

    Any ideas on how to get Parallel Task 1′s data refreshed or to wait on it, so that paralell task 2 can get it?

  11. Avatar of Ricky Spears

    Ricky Spears - September 14, 2012, 10:30 am

    johnfoll – Since the normal behavior for the workflow (in sequence) is to pause after creating a task until the task is complete, I dont think the workflow knows what the ID of the task is until after it is completed. So that’s probably why you’re getting the null value that’s causing the error due to coercion. Although I like the simplicity of having a single workflow that both assigns a task and sends and email, I just don’t think that’s going to be possible with the current architecture.

  12. Avatar of John Foll

    John Foll - September 17, 2012, 8:29 am

    I found a way to get the Parallel task to work. Create a Parallel Task, Step1) Put Collect Data from user, Step 2) Put a Step: Call it Email: In this Step 2) Add a Pause for 1 minute, Add Email Task: Add a Hyperlink in Email body for your link to the approval task (You can grab the Task ID from this Collect Data from user task, by using adding a Lookup for string: Data Source: “Association: Task List”, Field From Source: ID, Find the List Item: Field: Workflow Item ID, Value: Current Item:ID. This gets you the ID of the Task.) By running your Collect Data from user one time, in the List / Tasks from SharePoint web, click on the task, then Copy the URL from the web address bar and past into your email Hyperlink Address. Then change the ID, and put in the lookup from the Assocation Task list I just mentioned.”

    The only important thing is that this way makes you wait a minute before the Emails can get sent out for the Task, to make sure the Collect Data from user Task is started and saved its data into the Task List before sending the email.

    The reason I am using this Parallel Task, because I was having an issue where SharePoint was running my Task Workflow with steps that I had already deleted and running my new step, even after save and republishing many times! Probably storing in the temporary cache. So I decided to use this Parallel Task method instead. Cleanner, less object to have to worry about. I know I could have created a New Task Workflow with a New Name, and it probably work, but wanted to try this Parallel Task method again.

  13. Avatar of John Foll

    John Foll - September 17, 2012, 9:18 am

    There is an issue with this new way using a Paralell task: If you have multiple Collect Data From User Tasks, it isn’t distinquishing between them, and will return the first one it finds. I don’t know if there is a way to put multiple search criteria in the Lookup for a string or not.

  14. Avatar of Frances Garland-Guay

    Frances Garland-Guay - March 4, 2013, 10:21 am

    Hi Ricky,
    I have already created a collect data custom task, the issue I am facing is the link for the user to the exact task. I have customized the task by content type. I do not want them to link to the original form as it is an employee eval, so no access after they have reviewed the document. Can you please explain how to make this dynamic, I am having a problem with this string. Then I can move on to greater things LOL.
    thank you ahead of time!

Leave a Reply