Writing workflows implies sometimes having to navigate back and forth through the different activities. For example for taking the message of the last Activity, or taking the Assignee of the next Activity.
This post gives code samples for retrieving the last Activity Instance. This is the previous Activity Instance that was completed before the current one.
For the code-above we need to know the CurrentWorkItem, which is the WorkItem of the current item in the workflow.
Another utility method, based on GetLastActivityInstance() is GetLastActivityMessage(), as shown below:
/// <summary>
The code above is part of YAWF (Yet Another Workflow Framework).
This post gives code samples for retrieving the last Activity Instance. This is the previous Activity Instance that was completed before the current one.
/// <summary>
/// Return the last activity instance
from the current process instance
/// </summary>
/// <returns></returns>
protected ActivityInstance
GetLastActivityInstance() {
ActivityInstance activity =
CurrentWorkItem.Activity as ActivityInstance;
ProcessInstance processInstance = activity.Process
as ProcessInstance;
IList<ActivityInstance>
activities = new List<ActivityInstance>(processInstance.Activities);
for (int i =
activity.Position - 1; i >= 0; i--) {
ActivityInstance lastActivity = activities[i];
if (lastActivity != null)
{
return lastActivity;
}
}
Logger.Warn("AbstractHandler.GetLastActivityInstance:
Cannot retrieve previous Activity Instance");
return null;
}
For the code-above we need to know the CurrentWorkItem, which is the WorkItem of the current item in the workflow.
Another utility method, based on GetLastActivityInstance() is GetLastActivityMessage(), as shown below:
/// <summary>
/// Return the finishMessage of the
last activity in this workflow process
/// </summary>
/// <returns></returns>
protected String
GetLastActivityMessage() {
ActivityInstance lastActivity =
GetLastActivityInstance();
if (lastActivity != null)
{
return lastActivity.FinishMessage;
}
Logger.Warn("AbstractHandler.GetLastActivityMessage:
Cannot find previous Activity message");
return String.Empty;
}
The code above is part of YAWF (Yet Another Workflow Framework).
Comments