Tuesday, October 18, 2011

Workflow task link in email

Just wanted to do a quick post on a recent gotcha. I created a MOSS 2007 state machine workflow and added custom email activities to send emails notifying users of their tasks. I wanted to have a link in those emails that pointed directly to the user's task, ie the same link you get when you enable "Send e-mail when ownership assigned?" in the task list's Settings -> List Settings -> Advanced settings screen.

I thought I could simply reference the task's ListItemId property, but it kept coming up as -1. After finding an article on SharePoint Tricks, I realized I needed to create a Field variable for the ListItemId property, then reference the Field variable.

1. In the create task activity, create a Field from the ListItemId (by default it says -1).

2. The link in the email concatenates workflowProperties.SiteUrl, workflowProperties.TaskListUrl, "/DispForm.aspx?ID=", and finally createMyApprovalTask_ListItemId.ToString()


This will link directly to the user's task form on the SharePoint site.

That's it!

No comments:

Post a Comment