Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a workflow event receiver which is handling the WorkflowStarted and WorkflowCompleted events. I need to obtain references to the workflow list item and the workflow object to do some additional processing. How do I go about that?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Mihai,

You can have a look at this question on MSDN which will give you code reference to get the workflow association with Workflow Manager

And here is how you can get the item, history, tasks etc:

  public override void WorkflowStarted(SPWorkflowEventProperties properties)
   {
       base.WorkflowStarted(properties);

       SPSite site = new SPSite("SPURL");
       SPWeb web = site.RootWeb;
       SPList list = web.Lists["ListName"];
       SPWorkflowCollection workflowCollection = new SPWorkflowCollection(list);
       SPListItem item = null;
       SPList task = null;
       SPList history = null;
       foreach (SPWorkflow workflow in workflowCollection)
       {
           if (workflow.InstanceId == properties.InstanceId)
           {
               item = list.GetItemById(workflow.ItemId);
               task = workflow.TaskList;
               history = workflow.HistoryList;

           }
       }
   }
share|improve this answer
    
Thanks, this is just what I needed! –  Mihai Oct 15 '12 at 14:36
add comment

You can use SPWorkflowEventProperties class object like

properties.ActivationProperties.Workflow to get the reference of workflow.

properties.ActivationProperties.List to get the reference of list. And

properties.ActivationProperties.Item to get the reference of Item.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.