Thursday, August 13, 2009

Adding a Description for SharePoint Designer Workflow

I have seen this question in many places “How to add description for a SharePoint Designer Workflow?” I had the same requirement; googling does not give me the result to achieve the same :-). See the image of a sample workflow generated by SharePoint Designer.



Unfortunately, SharePoint Designer does not provide an option for adding workflow description. I have looked at the files which is generated by designer, but unsuccessful. See the files generated by a SharePoint Designer Workflow



The finally I decided to write a piece of code using SharePoint Object Model to achieve the same.

private void AddWorkflowDescription(string siteURL, string listName, string workflowName, string workflowDesc)
{
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
SPList _linksList = web.Lists[listName];

foreach (SPWorkflowAssociation _wfAssoc in _linksList.WorkflowAssociations)
{
if (_wfAssoc.Name.ToLower().Equals(workflowName))
{
_wfAssoc.Description = workflowDesc;
_linksList.UpdateWorkflowAssociation(_wfAssoc);
break;
}
}
}
}
}


Feature Activated Code

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
string _siteURL = "http://mossserver:4545/sites/Demo/";
string _listName = "Links";
string _workflowName = "workflow 1";
string _workflowDesc = "Workflow Descriptiopn updated by code";
AddWorkflowDescription(_siteURL, _listName, _workflowName, _workflowDesc);
}


I have added this code in my “Feature Activated” event. The following image shows a SharePoint designer workflow with description which is generated by the above code.



Note:
If you just want to run this code only once then create a Console Application / Windows application to execute the above code.

1 comment:

Unknown said...

Hi there, thats exactly what I would like to achive as well. But I am a "no coder" so, could you please explain what to do and how to do it with your bit of code?
I have 4 separate WF's that I would like to give different descriptions to.
Great job!