The following code sample shows how to read the next ActivityInstance in a workflow. Mind you that for this to work, the current Activity has to be finished. Only then a next Activity Instance is created, and can thus be retrieved:
The code above is part of YAWF (Yet Another Workflow Framework).
/// <summary>
/// Get the next ActivityInstance, if
there is one. If the current Activity has not finished, there is no next
activity.
/// </summary>
/// <returns></returns>
protected ActivityInstance
GetNextActivityInstance() {
ActivityInstance activityInstance =
CurrentWorkItem.Activity as ActivityInstance;
ProcessInstance processInstance =
activityInstance.Process as ProcessInstance;
IList<ActivityInstance>
activities = new List<ActivityInstance>(processInstance.Activities);
if (activityInstance.Position < activities.Count)
{ //Position is 1-based
return activities[activityInstance.Position];
} else {
return null;
}
}
In a similar fashion, you can retrieve the next manual Activity:
/// <summary>
/// Get the next manual
ActivityInstance, if there is one.
/// </summary>
/// <param
name="activityInstance">current ActivityInstance</param>
/// <returns></returns>
protected ActivityInstance
GetNextManualActivityInstance() {
ActivityInstance nextActivity =
GetNextActivityInstance();
if (nextActivity != null)
{
TridionActivityDefinition activityDefinition =
nextActivity.ActivityDefinition as TridionActivityDefinition;
if (String.IsNullOrEmpty(activityDefinition.Script))
{
return nextActivity;
}
else {
Logger.Warn("AbstractHandler.GetNextManualActivityInstance:
Next activity is not a manual activity! This is not supported...");
}
}
return null;
}
Note how the check is done to determine a manual Activity: String.IsNullOrEmpty(activityDefinition.Script). There is currently no other way to determine the type of an Activity (manual vs automatic).
For the code-above we need to know the CurrentWorkItem, which is the WorkItem of the current item in the workflow.
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).
Comments