In The Mix

As a SharePoint architect I have the business behind me and the Developers and IT Pro on my shoulders.

BDC Question June 26, 2009

Filed under: Poll,Question,SharePoint — fmuntean @ 4:59 pm

This question is for all my readers. Please take few seconds or so and respond to the following question:

“Is Business Data Catalog a read only view into the Line Of Business data?”


SharePoint Workflow Task Reassignment

Filed under: SharePoint — fmuntean @ 4:37 pm

How to implement task reassignment inside SharePoint Workflow when you have a lot of tasks.

The problem: “Find a method to enable users to reassign tasks using a friendly method.”

The solution: “Add a link on the task edit page that points to another page that will do the reassignment”.


Now that being said I will always recommend that you don’t change any out of the box files in SharePoint.

So how we can do it? Easy.

Implement a custom Content Type derived either from the Task Content Type or InfoPath Task Content Type and redefine the edit page with your own. From here everything is peanuts and a lot of implementation work.

You can control the link to reassigned the task using extended properties. and can return extra information like comments and user id who reassigned the task into extended properties too.

As from the reassign aspx page you have direct access to the task item you can change security too right there.

Just be careful when and how you update the task item so you don’t get more than one task changed event back to the workflow or event receivers.


SharePoint Task Invalid BeforeProperties Fix

Filed under: SharePoint — fmuntean @ 4:18 pm

When working with tasks in a SharePoint workflow project you can get an event when a task changed but is hard to actually detect what changed as the event does not return enough information.


The following picture shows the regular flow to work with a task in workflow framework: image

So the minimum activities required are:

  • CreateTask to create the task
  • While  to wait until the task is considered completed
  • OnTaskChanged to receive any changes to the task
  • CompleteTask to complete the task and continue.

All the task related activities needs to be bind to the same correlation token. If your workflow will have multiple workflow make sure that you are creating multiple correlation tokens for each task.

  Now there are few other properties that are used during the lifetime of the task. I will only mention here the properties that are specific to the problem at hand

CreateTask activity needs to have the TaskProperties bind so it can use it to create the task item.

OnTaskChanged activity needs to have both AfterProperties and BeforeProperties bind so it can fill with values when your code is called.


Now the problem is that when the OnTaskChanged invoked event gets called the BeforeProperties seems to not contain any data where the AfterProperties seems to contain the current information.

Jus taking the example of checking to see if the task was reassigned by using the AssignedTo property for before and after properties as miss-directed by the MSDN and SDK does not work because the BeforeProperties.AssignedTo is null most if not all the times.

So what can we do now?

Let’s think how else we can get the before properties:

When we create the task we set the TaskProperties.AssignedTo to a person or group that we want to execute on the task. First time when the task is changed in any way we get the event with AfterProperties. Now we know if the AssignedTo was changed by checking if it is different than the original one that we specified when we created the task. If after that we copy the AssignedTo from AfterProperties into the TaskProperties when the task gets changed we can detect if the AssignedTo changed without using the BeforeProperties at all.

This is my solution:

  1. Forgot about BeforeProperties.
  2. Each time when a task gets changed detect the changes by checking AfterProperties against TaskProperties.
  3. After you execute the necessary code into the change event copy all necessary properties from AfterProperties back to the TaskProperties (this is your before properties now that you cache inside your workflow)
  4. Do not just  blindly assigned the AfterProperties over the TaskProperties as it will not contain all the properties all the time. AfterProperties contains only the task item properties that have changed so you will need to manually parse it back into the TaskProperties.

If you are still with me and your head did not explode over this explanation drop me a line.