7

I am relatively new to SDL Tridion and working on the SDL Tridion 2011 two step workflow process.

I want to get the ApprovalStatus information in the Event System when the Workflow Activity is finished.

Can someone help me and tell me if it is possible to retrieve this information?

2 Answers 2

7

You could directly get the approval status from the Activity Definition.

[TcmExtension("ActivityRelatedEvent")]
public class ActivityRelatedEvent : TcmExtension
{
    public ActivityRelatedEvent()
    {
        EventSystem.Subscribe<ActivityInstance, FinishActivityEventArgs>(ActivityFinishedEventHandler, EventPhases.Processed);
    }

    public void ActivityFinishedEventHandler(ActivityInstance activityInstance, FinishActivityEventArgs e, EventPhases phase)
    {
        ApprovalStatus approvalStatus = ((TridionActivityDefinition) activityInstance.ActivityDefinition).FinishApprovalStatus;
        if (approvalStatus != null)
        {
            Logger.Write(approvalStatus.Id.ToString());
            Logger.Write(approvalStatus.Title);
        }
    }
}
0
4

Welcome to the Tridion Community and asking a clean question.

To get this information you may try the following Event System code block below:

private static void WorkflowEvent(ActivityInstance activityInstance, FinishActivityEventArgs args, EventPhases phase)
{
    IEnumerable<WorkItem> workItems = activityInstance.WorkItems;
    WorkItem currentWFItem;
    using (IEnumerator<WorkItem> iter = workItems.GetEnumerator())
    {
        iter.MoveNext();
        currentWFItem = iter.Current;
    }

    if (currentWFItem != null)
    {
        Component currentComponent = (Component)currentWFItem.Session.GetObject(currentWFItem.Subject.Id);
        ApprovalStatus approvalStatus = currentComponent.ApprovalStatus;
    }
}
2
  • 2
    Consider using LastOrDefault instead of that GetEnumerator loop - or at least simplify it to foreach (WorkItem item in workitems) :) Commented Oct 15, 2013 at 15:07
  • Agreed Peter; I have copied it from one of my very old post from old tridion forum without realizing the poor performance issue in it Commented Oct 15, 2013 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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