Tridion Workflows - How to get a component in an Activity in an event handler

I need to get a component related to activity in an event system.

I am trying to get the component id using:

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) { } } } } 

we will try different options:

  Component comp = (Component)activityInstance.ProcessInstance.Item; 

But this solution returns zero.

Then I found the following solution on the Internet:

  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; 

But the ProcessHistory object is null.

How to determine the component associated with ActivityInstance?

Thanks.

+6
source share
3 answers

After looking at the functionality Guskermitt needed, I showed him a tidier way to do what he needed. In short, an EventSystem is not required in this case.

Its purpose is to send an email after the component is approved, this approach will be as follows:

  • Add new automatic activity to the workflow.
  • Create a new .NET assembly, in this case the C # class, to do what it needs.
  • Register the assembly in the GAC.
  • Add logic to a new automatic activity in the workflow to use the .NET assembly.

2 #

 [ProgId("WfHelper")] [ComVisible(true)] public class Helper { public void SendMail(string workItemId) { var session = new Session(); . . . 

4 #

 dim helper set helper = CreateObject("WfHelper") call helper.SendMail(CurrentWorkItem.ID) set helper = nothing FinishActivity "Email has been sent" 
+5
source

ActivityInstance has a WorkItems property (inherited from Activity ) that contains a link to your Component .

+3
source

OnActivityInstanceFinishPost means your activity is complete. Therefore, no more work is associated with it. However, you get an instance of the process and its associated work item. If you get zero there, then it indicates that your workflow has completed and the component has exited the workflow. If you look at your code, it is likely that your ProcessInstance will terminate (it will not be empty, but it will not have any element associated with it).

I suspect you read this post http://www.tridiondeveloper.com/autopublishing-on-workflow-finish , suggesting a look in the story. You looked into the story through the CM GUI, is there a story element there? If this is not the case, then why are you getting null. The process processing process moves to history upon completion. Therefore, double-check that you are indeed in the last workflow before looking at the story.

Looking at your code, it seems that the error lies in trying to get the history object using activityInstance.ProcessInstance.ID. GetObject () should return an element, but your throw in ProcessHistory should break, and then you will calmly have an exception. You need to pass the history identifier, not the ProcessInstance identifier, as follows:

 ProcessHistory hist = (ProcessHistory)tdse.GetObject(processHistoryId, EnumOpenMode.OpenModeView, Constants.URINULL, filter); 
+2
source

All Articles