Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion Workflows - How to get the Component at the Activity in Event Handler

I need to get the component associated to a Activity at the event system.

I try 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 try different options:

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

But this solution returns a null.

Then I found in internet the next solution:

 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 can I determine the component associated to the activityInstance?

Thank you.

like image 428
Guskermitt Avatar asked Feb 13 '13 08:02

Guskermitt


2 Answers

After reviewing the functionality needed by Guskermitt, I've shown him a neater way to do what he needs to do. In short, EventSystem is not needed in this case.

His goal is to send an email after a component has been approved, the approach will be the following:

  1. Add to workflow a new automatic activity.
  2. Create a new .NET assembly, in this case a C# class to do what he needs to do.
  3. Register the assembly in the GAC.
  4. Add logic in the new automatic activity in 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"
like image 95
Asier Fernández Avatar answered Oct 01 '22 22:10

Asier Fernández


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

like image 44
Arjen Stobbe Avatar answered Oct 01 '22 22:10

Arjen Stobbe