Discover Us

Chimera
Home > Capabilities > Technical Articles > Custom Work Flow in WSS

Custom Workflows in WSS using custom sharepoint initiation forms

Workflows can be created using Share point designer easily, but the thing is, it has only a set of Pre-defined activities. If we want to create our own activity, then we can use Custom Workflows which can be created with the help Workflow Foundation in VS 2008. This article explains a simple custom workflow with a custom workflow initiation form to collect certain data and pass it to the workflow.

Creating Custom Workflow in VS 2008

  1. Start Visual Studio 2008.
  2. New Project.
  3. Under the Office Project Type, select the SharePoint 2007 Sequential Workflow project template.
  4. In the Name box, type CustomWorkFlow. Click OK.
  5. Type a valid SharePoint Web URL. The example uses http://spserver/.Click Next.
  6. Select a library or list to associate with your workflow, and click Next.
  7. Select how a workflow can be started, Manually by users or When an Item is created. Click Finish.
  8. Create a folder /file structure as shown in the figure below. You might be required to move the feature and workflow xml files to the appropriate directory.
  9. Add the “onWorkflowInitiated” to the designer.
  10. Drag the Code control into the page and rename it SendMail.
DNN & LLBGenPro

The workflow looks like as above, Now we can write our c# code to send an email to a particular person.

Creating a sharepoint custom workflow initiation form

Consider that we have a pass the Sender mail id as parameter to this work flow which can be selected dynamically by the user. We can add an aspx page in our project with required controls like a drop down (contains the list of Sender mail ids) and a Send Button and use it as an initiation form.

In the above example we have created a custompage.aspx (refer the figure above), while form loading we are loading items of the drop down control from the WSS list. To make sure that this page is called during the workflow initiation pls use the following in the workflow.xml file.

Under the <Workflow> tag add the following code.

InstantiationUrl = "_layouts/SampleSequentialWorkFlow.aspx"

which informs WSS to use our instantiation form when the Workflow is activated.

Then On the Button click event we have to write the follow code to pass the selected email id from the drop down to the workflow as a string.




Sample Code:

SPWorkflowAssociation m_assocTemplate;
SPWorkflowTemplate m_baseTemplate;
SPWeb m_web;
SPList m_list;
SPListItem m_listItem;
string m_lietItemName;
string m_listItemUrl;
string m_workflowName;

m_web = SPControl.GetContextWeb(this.Context);
m_list = m_web.Lists[new Guid(Request.QueryString["List"])];
m_listItem= m_list.GetItemById( Convert.ToInt32(Request.Params["ID"], CultureInfo.InvariantCulture));
Guid associationId= new Guid(Request.Params["TemplateID"]);
m_assocTemplate = SPWorkflowAssociationCollection.GetAssociationForListItemById(m_listItem,associationId);
m_workflowName = m_assocTemplate.Name;
m_web.Site.WorkflowManager.StartWorkflow(m_listItem,m_assocTemplate, “Parameter”);

Accessing the initiation parameters in the sharepoint workflow code

In the Workflowload activity we can use the fllowing code and get the parameter values

public SPWorkflowActivationProperties workflowProperties = newSPWorkflowActivationProperties();
String ParamValue = workflowProperties.AssociationData;

Remember that values passed in the “StartWorkflow” is accessed at this stage for our processing.




Deployment:

Add a intall.bat file which contains the following code to register the workflow that we created in the WSS 3.0

Intall.bat contains

@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"

Echo Copying files
xcopy /e /y TEMPLATE\* %TEMPLATEDIR%

Echo Installing feature
%STSADM% -o InstallFeature -filename CustomWorkFlow\feature.xml -force

Echo Restart IIS Worker Process
IISRESET

Also incude the following code in application propertie’s Post Build Event

cd $(ProjectDir)
Install.bat

Now on every build, the Workflow will be deployed in the WSS for to access and test.

Contact us to know more

Want to know more on our video streaming solutions

How we engage

Chimera's project management and delivery models are driven by our clients comfort, project dynamics and other factors like timelines, cost etc. Click here to know more about our "Delivery Models"