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?

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);
        }
    }
}
| improve this answer | |
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;
    }
}
| improve this answer | |
  • 2
    Consider using LastOrDefault instead of that GetEnumerator loop - or at least simplify it to foreach (WorkItem item in workitems) :) – Peter Kjaer Oct 15 '13 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 – Pankaj Gaur Oct 15 '13 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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