Microsoft Office SharePoint Server (MOSS) 2007 provides the ability to create rich, custom workflow solutions built upon the Windows Workflow Foundation (WF) framework. Workflow solutions provide a useful way to define and automate information based processes, which may or may not require human interaction at various points in the process. This post will examine how to customise and extend customised workflows through passing parameters via association and initiation events.
A workflow association describes the process of linking a workflow to an object within SharePoint, such as a list. A workflow initiation event occurs every time a workflow instance initiates. Parameters passed via association are common to all workflow instances on that particular object. Parameters pass via initiation relate only to an individual workflow instance.
MOSS provides a useful way of leveraging both workflow association and initiation, at the time they occur, to pass parameters into the workflow. The easiest way to allow users to pass parameters into a workflow is through the implementation of Microsoft InfoPath forms. It is possible to use ASP.NET pages to capture user input but MOSS provides out-of-the-box Web Part pages to display Infopath forms at the time the workflow is associated and initiated. For instance, an association form could capture the location of another SharePoint repository which the workflow could use to route all pieces of content to on that particular list. When a workflow must make ad-hoc decisions on an instance to instance basis, then initiation forms are more appropriate to parameterise workflows.
Code Example: Accessing parameters passed via an association form
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
private string assocParam = default(String);
workflowId = workflowProperties.WorkflowId;
XmlSerializer serializer = new XmlSerializer(typeof(myFields));
XmlTextReader reader = new XmlTextReader
(new StringReader(workflowProperties.AssociationData));
myFields assocForm = ( myFields)serializer.Deserialize(reader);
assocParam = assocForm.field1;
}
The two highlighted lines of code in yellow demonstrate how to declare a local variable within the workflow and then programmatically capture the parameter from our deserialized association form.
Association and initiation forms provide a rich and scalable way to pass a variety of information into all or individual workflow instances to extend the functionality. The opportunities for scalability and abstraction increase when we consider that we can connect these workflows to the WF Rules Engine. This then provides a method to separate the workflow process from the rules that govern it. These concepts will feature in further posts.
Comments