These functions are available in Workflow Engine ≥ 4.0
Annotations are a set of records, a key (or name) - a value you can add to your Activities and Transitions in the designer. Annotations could be called "Activity and Transitions Custom Parameters" or "Activity and Transitions additional attributes", but we have chosen the term "Annotations", it is unambiguous and does not overlap with other WFE functions. The most essential information you need to know about annotations is the following:
It is very easy to read annotation value from code (it can be your Actions Code or any other server code). If you read annotations values from Actions, there is always a reference to the current ProcessInstance
. Use the following code tp get annotations values as string:
var processScheme = processInstance.ProcessScheme;
string valueFromActivity = processScheme.GetActivityAnnotation("ActivityName", "AnnotationName");
string valueFromTransition = processScheme.GetTransitionAnnotation("TransitionName", "AnnotationName");
If you are using JSON as annotation value and you've got a type you can deserialize this JSON into, get this type values instantly:
var processScheme = processInstance.ProcessScheme;
YourCustomType valueFromActivity = processScheme.GetActivityAnnotation<YourCustomType>("ActivityName", "AnnotationName");
YourCustomType valueFromTransition = processScheme.GetTransitionAnnotation<YourCustomType>("TransitionName", "AnnotationName");
You can also read annotations values from the objects of the ActivityDefinition
and TransitionDefinition
type. For example, the following code will read annotations from the executing Activity and Transitions.
string valueFromActivity = processInstance.ExecutedActivity.GetAnnotation("AnnotationName");
string valueFromTransition = processInstance.ExecutedTransition.GetAnnotation("AnnotationName");
Same for typified annotations:
YourCustomType valueFromActivity = processInstance.ExecutedActivity.GetAnnotation<YourCustomType>("AnnotationName");
YourCustomType valueFromTransition = processInstance.ExecutedTransition.GetAnnotation<YourCustomType>("AnnotationName");
If you have decided to get annotations values outside actions, you will have to get the object of the ProcessDefinition
type first:
var processSchemeByProcessId = WorkflowInit.Runtime.GetProcessInstanceAndFillProcessParameters(processId);
var processSchemeByCode = WorkflowInit.Runtime.Builder.GetProcessScheme(schemeCode);
After that to get annotations values use methods described above.