Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Start a Visual studio 2010 sharepoint workflow programatically

$
0
0

Hi all,

I have created a visual studio 2010 sequential workflow for my SharePoint form library. I want to start this workflow when a field in the library equals a certain value. On creation in visual studio, I selected the option of starting the workflow "when an item is changed" but this option doesn't fit my clients scenario as the item has to be changed 3 times before the workflow should start.

I have since opted to try and start the workflow programmatically. I have found a few links on-line but no one explicitly states where the code snippets should be placed, what kind of project the code should be put in, and how it is triggered. 

Here is my code and it doesn't work.

public override void ItemUpdated(SPItemEventProperties properties)
       {
           base.ItemUpdated(properties);



           if (properties.ListItem.ParentList.TemplateFeatureId ==
               new Guid("70c3d635-e72d-4a39-a8a2-81de96011aed"))

           {
               if (properties.ListTitle == "my library") {

                   SPWorkflowManager wfManager = properties.ListItem.ParentList.ParentWeb.Site.WorkflowManager;

                   SPWorkflowAssociationCollection wfAssociationCollection =
                       properties.ListItem.ParentList.WorkflowAssociations;

                   //SPWorkflowAssociation wfAssoc =



                   foreach(SPWorkflowAssociation wfAssociation in wfAssociationCollection)

                   {
                       SPItem doc = properties.ListItem;
                       if (doc["Form Status"].ToString() == "Approval 3")
                   {
                       wfManager.StartWorkflow(properties.ListItem, wfAssociation,
                           wfAssociation.AssociationData, true);

                       break;
                   }
                  }

I await your responses.

Thanks.


Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>