Sorry for the long break in my blogging. I’ve been a bit tied up to say the least. I got back from Redmond last week, and I took this picture with my phone as the plane rose above the clouds and I saw Mount Ranier for the first time on this trip. Behind that you can also see Mt. St. Helens. Gotta say, it was a lot better in person. One thing I don’t like about visiting the Seattle area is the terrible GPS reception there. Can anyone explain that? Besides that, I always love visiting the Microsoft campus – damn it must be fun working there.
So, besides that.
Let us talk about authoring custom workflows in SharePoint 2007 using SharePoint designer. The best way to explain anything is to cook up a real world problem and then implement it. So let us say, I wish to create a document library where all meeting minutes are stored. Soon as a new meeting minute is dropped in the document library, I'd like to allow the user to send out an email to a select group of individuals. This could be easily achieved using a number of ways.
a)You can subscribe the relevant folks to alerts – but the email text is not configurable.
b)You can tap into the ItemAdded or ItemChanged event and send an email – but that will require you to write some code.
c)Or, you can author a custom workflow, which can perform the activity of sending out an email.
Of these three, I like #c the most because it requires the least code, and offers the most extensibility. In fact, what if I wanted to allow the end user to be able to specify a custom message on top of the email being sent out? This is something that you would have a hard time achieving through #b, pretty much impossible using #a, but darned easy to do using #c.
So let us solve this problem using #c – authoring a custom workflow.
To begin, let us set up a document library that will hold my meeting minutes. I will then attach a workflow to this document library. As usual, go to Site Actions -> Create
Click on “Document Library” under “Libraries”
Fill out the necessary details –
And click “Create” as shown above to create your document library.
Next, fire up SharePoint designer, and use File -> Open Site to open the site that contains the above document library inside SharePoint designer. You should see the site structure opened in SharePoint designer as shown below.
Next, in SharePoint designer, create a new workflow as shown below:
Fill in the necessary details as shown below:
Now, in my workflow, I wanted to allow the end user to be able to specify his custom message on top of the email that was being sent out. In order to do so, I will click on the “Initiation” button, and specify a field called “CustomMessage” as shown below:
I will then click on “Next” and specify custom conditions and actions as shown below.
When I click the “this message” hyperlink above, I can specify the details of the message as shown below.
As you can see, I have also extracted stuff out of the metadata about the list and the item to create a more meaningful message. This extraction can be done using a dialogbox as shown below.
Go ahead and finish the workflow. You would note that a workflow has been added to your site as shown below.
Let us now go back to the browser, and go ahead and upload a document in this document library. This can be seen as below:
Now in the uploaded document, let us start the workflow. Go ahead and click on “Workflows” as shown below.
Click on “Email WF”
Specify your custom message –
And bingo – check your inbox – you should see an email. w00T!! J. Oh, and need I mention, you can make this workflow much more complex to reflect your business processes. Heck you can even supplant it with custom activities.
Now there is an interesting gotcha here though. What if the workflow was set to start automatically? GO ahead – try it out.
You would note that in such a situation, you cannot pop up the initiation aspx. Hmm. There are two workarounds to that problem.
a)Request initiation data when the file is being uploaded – basically as custom fields on the document library or list.
b)Using Visual Studio create a workflow and create input forms using Infopath. The automatic workflow requires user input using those forms. I hope to blog about that soon (wish I had more time).
Hope you found the above helpful. Adios.
Thou shalt -