Archive

Archive for July, 2011

Workflow Development Life Cycle: It Can Get Messy!

July 9th, 2011 No comments

As you know, one of the investments areas in workflows in sharePoint 2010 is the full workflow development life cycle. This cycle starts with information workers modeling the workflows in Visio which can then be imported to SharePoint Designer (for further declarative customizations) and finally to Visual Studio 2010 for developers for hard-core coding and customizations.

Well, the life cycle (Visio >SPD > Visual Studio) may seem to be straightforward, however, it’s not always a clean process! For example, during modeling if someone decides to have an approval activity in the model, below is what the poor developer will get in the workflow design canvas in Visual Studio 2010:

visio.png

Workflow modeling and development, like anything else in SharePoint 2010, requires planning and education for all project stakeholders!

Categories: SharePoint 2010 Tags:

Now Available for Pre-order: SharePoint 2010 Enterprise Architect’s Guidebook

July 6th, 2011 No comments

I am pleased to announce that the book I was a co-author for, with Brain Wilson, Bill Baer, Martin Kearn and Joel Olson, is now available for pre-order.

Please check it out if you are intrested:

http://www.amazon.com/SharePoint-2010-Enterprise-Architects-Guidebook/dp/0470643196

Categories: General, MOSS 2007, SharePoint 2010 Tags:

Programmatically Associating a Workflow to a Site

July 5th, 2011 6 comments

When you deploy a site-level workflow using Visual Studio 2010, Post-Deployment build configuration takes care of activating the workflow feature, and programmatically associates the workflow to the site.

When you deploy the wsp package using PowerShell or stsadm , the magic won’t happen! So, if you go to View All Site Content > Site Workflows, the page is pretty empty with a message saying that “there are no workflows currently available to start on this site”

noworkflow.PNG

What you need to do is to put the following code in your feature receiver:

[CSharp]
private string workflowTemplateBaseGuid = “1e547b46-3d00-43b0-928d-4fe103b92fcb”;
private string workflowAssociationName = “My Workflow”;
private string workFlowHistoryListName = “Workflow History”;
private string workFlowTaskListName = “Workflow Tasks”;

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
var site = properties.Feature.Parent as SPSite;
var web = site.RootWeb;
SPWorkflowTemplateCollection workflowTemplates = web.WorkflowTemplates;
SPWorkflowTemplate workflowTemplate =
workflowTemplates.GetTemplateByBaseID(new Guid(workflowTemplateBaseGuid));

if (workflowTemplate != null)
{
// Create the workflow association
SPList taskList = web.Lists[workFlowTaskListName];
SPList historyList = web.Lists[workFlowHistoryListName];
SPWorkflowAssociation workflowAssociation =
web.WorkflowAssociations.GetAssociationByName
(workflowAssociationName, CultureInfo.InvariantCulture);

if(workflowAssociation ==null)
{
workflowAssociation = SPWorkflowAssociation.CreateWebAssociation
(workflowTemplate, workflowAssociationName, taskList, historyList);
workflowAssociation.AllowManual = true;
workflowAssociation.Enabled = true;
web.WorkflowAssociations.Add(workflowAssociation);
}
}
}
[/CSharp]

One thing to note is that in sharePoint 2010, SPSite.SPWorkflowManager.GetWorkflowTemplatesByCategory() doesn’t properly return the workflow template collection like SharePoint 2007. So, I had to fall back to the traditional way of using SPWeb.WorkflowTemplates to get my workflow template and create the SPWorkflowAssociation object.

Obviously, in your FeatureDeactivating code, you need to add the necessary code to remove the current instances of the workflow; otherwise if you deactivate the feature and activate it, the workflow doesn’t show up again in View All Site Content> Site Workflows again. A no-code workaround for this issue is to go to Site Settings > Site Administration > Workflow Settings; and remove the instance manually.

Categories: SharePoint 2010 Tags: