title: Tridion Workflows - How to get the Component at the Activity in Event Handler
body: <p>I need to get the component associated to a Activity at the event system.</p>
  
  <p>I try to get the component ID using:</p>
  
  <pre><code>    public void OnActivityInstanceFinishPost(ActivityInstance activityInstance, string finishMessage, string nextActivity, string dynamicAssignee)
      {
  
          if (activityInstance.ProcessInstance.ProcessDefinition.Title.Equals("Component Process IESE"))
          {
              if (activityInstance.ActivityDefinition.Title.Equals("Create or Edit Component"))
              {
                  WFE workflow = tdse.GetWFE();
                  try
                  {
                      Component comp = (Component)activityInstance.ProcessInstance.Item;
  
                      XMLReadFilter filter = new XMLReadFilter();
                      String processHistoryId = activityInstance.ProcessInstance.ID.Replace("131076", "131080");
  
                     ProcessHistory hist = (ProcessHistory)tdse.GetObject(activityInstance.ProcessInstance.ID, EnumOpenMode.OpenModeView, Constants.URINULL, filter);
  
                  }
                  catch (Exception e)
                  { }
  
              }
          }
      }
  </code></pre>
  
  <p>we try different options:</p>
  
  <pre><code>    Component comp = (Component)activityInstance.ProcessInstance.Item;
  </code></pre>
  
  <p>But this solution returns a null.</p>
  
  <p>Then I found in internet the next solution:</p>
  
  <pre><code> XMLReadFilter filter = new XMLReadFilter();
   String processHistoryId = activityInstance.ProcessInstance.ID.Replace("131076", "131080");
  
   ProcessHistory hist = (ProcessHistory)tdse.GetObject(activityInstance.ProcessInstance.ID, EnumOpenMode.OpenModeView, Constants.URINULL, filter);
   Component comp = hist.Item as Component;
  </code></pre>
  
  <p>But the ProcessHistory object is null.</p>
  
  <p>How can I determine the component associated to the activityInstance?</p>
  
  <p>Thank you.</p>