Updating a Custom Task Field With Item Data using SharePoint Designer

1 Comment

Imagine you have a list or library item of a custom contenttype and you want a user to update an existing field of the contenttype via a “Collect data from a user” action. Further you want the Task to show the current value of this existing Field when it is edited by the user. After completing the Task, the new value of the field should be saved to the original Item on which the workflow was started. A complete circle:

First you need a custom contenttype. I created an example contenttype with 1 extra column: “Some Extra Comment”. The value of this column will be sent to the Task. Add the newly created contenttype to a Document Library.

Next in SharePoint Designer you create a new reusable workflow for the contenttype you have just created. Add the action “Collect data from a user” to the workflow. Enter a title (I named it “Get some data”) and optional a description for the action and click next. Now add a field named “ExtraComment” of type “Single line of text”:

Click next and leave the default value empty. Click finish. Add a “User” to you “Collect data from a user” action. Your action should now look something like this:

Now this is very important: The ID of the newly created Task will be stored in the local workflow variable “collect”.

Next save and publish the workflow and associate the workflow with the contenttype:

Now add a document to your library with your newly created contenttype and run the workflow on the document. This is necessary because the custom column in your “Collect data from a user” action (“ExtraComment”) has to be added to the Task list. This is done at the moment a Task is created.

So go to your task list and be sure a task is created in the task list. Next complete the task. The workflow on the original item should now also be completed.

Now re-open the workflow in SharePoint Designer and add the “Set Field in Current Item” action. This action will be executed AFTER the Task has been completed. So “ExtraComment” will have its new value and we have to get this value from the task in the tasks list:

Everything is pretty standard: the datasource to get the value from is “Tasks”. The field is “ExtraComment”. The specific item the value should come from is the value where ID equals “collect” (which is, as you will remember, the ID of the task that was created).

Your workflow should now look something like this:

Publish your workflow. At this moment all you need to do is make sure that when the task is created, it gets the current value of “Some Extra Comment” from the item the workflow is run on. For that we need to create a List Workflow on the task List:

Add a “Set Field in Current Item” Action. Now this time the datasource is the document library that has the original workflow item (in my case I used “Shared Documents”). The field you want the value from is “Some Extra Comment” and the specific item you want this data from is where the ID corresponds to the field “Workflow Item ID”:

Your Task List workflow should look something like this:

Publish your Task List Workflow.

Now make sure that the Task List Workflow is automatically started when a Task is created. You need to do this because the data from the original Item has to be retracted on the moment of Task creation. You can do this in SharePoint Designer under “List and Libraries”, next select the Task list and change the settings of your workflow to:

Save the settings. Everything should work now! Add a document to your library and set “Some Extra Comment” to “This is my first comment”. Now run the workflow and open your Task. It should look something like this:

Add some text to the “ExtraComment” field and complete the Task:

Now go back to your your original item. The workflow should be completed. Next select “View Properties”:

A complete circle!


DevDays Netherlands 2011

Leave a comment

April 28 and april 29 we (me and some colleagues from QNH) went to the DevDays in The Hague (Netherlands). I decided to write a small summary about what we saw and to give some resources for further reading. So here it goes:

Azure and AppFabric
There were al lot of sessions about Windows Azure. Everything indicates that the cloud is really taking a flight in 2011/2012. We got an introduction to the 3 different middle-ware services that Azure at the moment offers:

  1. the service bus
  2. access control
  3. cache service (this service went on-line on the 29th of April 2011)

With the use of Azure AppFabric it is possible to build composite applications that make use of each of these services. For more information on Azure AppFabric see: http://www.microsoft.com/windowsazure/AppFabric/Overview/default.aspx. There is also a server version of AppFabric which you can find on http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=467e5aa5-c25b-4c80-a6d2-9f8fb0f337d2. AppFabric builds on top of the “Application server” role of Windows Server.

Next went to see the presentation “LighSwitch Beyond the basics” by Beth Massi. LightSwitch is a framework on which you can build mash-up applications in Visual Studio really fast. With LightSwitch you can connect to a lot of different datasources. Datasource types include SqlServer, WCF RIA and yes: SharePoint lists and libraries. Next you can create a datamodel based on the datasources. For example: you can connect your SQL table to a SharePoint Library. The creation of the datamodel feels a lot like creating a datamodel in MS Access. It is also possible to add validation to your fields or entities (like: the date in this date-field should be after 1/1/1990). On top of your datamodel you can create CRUD (Create, Read, Update & Delete) screens based on SilverLight 4. And all I described above can be done without writing a single line of code!

However, the best thing about LightSwitch is that you can write code if needed. Events in the validation, the datasources and the views can be overridden. Further it is possible to create your own SilverLight controls that can be used in the views (for example the Bing Maps Control). LightSwitch is still in beta, but I think it’s definitely worth taking a look: http://msdn.microsoft.com/en-us/lightswitch/ff796201. I will be writing some more posts on LightSwitch and SharePoint.

We went to see Scott Hanselman’s presentation about MVC 3 (somehow the Microsoft MVC framework reminds me a lot about the Java Struts framework). Scott gave an introduction to “Razor”, a syntax for creating ‘cleaner’ mark-up in hybrid html/code aspx pages (something, which I remember, was also always an issue with Java JSP pages) For an introduction to Razor see Scott Guthrie’s blog http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx.

Scott talked about Modernizr. With the coming of HTML 5 and CSS3 there are browsers that support the new features and browsers that do not yet support these features. When you create a new website you want to make use of the newest features, but you also want your website still to work on older browsers. With the Modernizr framework you can make your website backwards compatible. In other words: if the browser supports the new technologies, it will make use of these new technologies. If it does not, instead it will render controls and features that it does support. For more information on Modernizr see http://www.modernizr.com/.

Something else he talked about was NuGet (see http://nuget.codeplex.com/) a tool for making use of third party libraries in .Net development easier. NuGet automates the tasks of downloading and incorporating third party libraries (including dependencies) in a project.

Here’s an impression of the DevDays 2011 The Hague Netherlands (the photo was taken with my phone so it is not really good quality…):

DevDays 2011 The Hague