Sometimes in practice, you need to get the last manual activity of a workflow. This is the last activity that was performed before the current activity and that is not automatic (i.e. was performed by a user).
A use case is to retrieve the message that the user completed his manual activity with.
For the code-above we need to know the CurrentWorkItem, which is the WorkItem of the current item in the workflow.
The code above is part of YAWF (Yet Another Workflow Framework).
A use case is to retrieve the message that the user completed his manual activity with.
/// <summary>
/// Return the last manual activity
instance from the current process instance
/// </summary>
/// <returns></returns>
protected ActivityInstance
GetLastManualActivityInstance() {
ActivityInstance activity =
CurrentWorkItem.Activity as ActivityInstance;
ProcessInstance processInstance = activity.Process
as ProcessInstance;
List<ActivityInstance>
activities = new List<ActivityInstance>(processInstance.Activities);
for (int i =
activity.Position - 1; i >= 0; i--) {
ActivityInstance lastActivity = activities[i];
TridionActivityDefinition activityDefinition =
lastActivity.ActivityDefinition as TridionActivityDefinition;
if (String.IsNullOrEmpty(activityDefinition.Script))
{
return lastActivity;
}
}
Logger.Warn("AbstractHandler.GetLastManualActivityInstance:
Cannot find previous manual Activity Instance");
return null;
}
/// <summary>
/// Return the finishMessage of the
last manual activity in this workflow process
/// </summary>
/// <returns></returns>
protected String
GetLastManualActivityMessage() {
ActivityInstance lastActivity =
GetLastManualActivityInstance();
if (lastActivity != null)
{
return lastActivity.FinishMessage;
}
Logger.Warn("AbstractHandler.GetLastActivityMessage:
Cannot find previous manual Activity message");
return String.Empty;
}
Comments