Code Activity
The Code activity allows you to write custom logic; therefore, you can augment the functionality of a workflow to meet your needs.
The following functions are supported for the Code activity:
Example supported Code functions | Unsupported Code functions |
---|---|
Variable declarations and assignments (Dim i as Integer; i = 5) | Declaring a class, interface, structure, or enum. |
Math operations (i = 5*j -100) | Declaring a subprocedure or function. |
Flow control logic (If/Else statements, While loops, goto’s) | Declaring a namespace. |
Calling member methods of a declared object, or an object passed in as a parameter (MyObj.DoSomething()) | Importing a namespace. |
Calling static methods on known/imported types | Returning a value: Code activities have no return values, they must provide output through code parameters (for example, you can call ‘return’ to indicate you want the snippet to end, but you cannot call ‘return true’). |
Try-catch statements | Directly accessing properties of the workflow (activities, variables, and so on). You must pass any values you want to work with as parameters. |
Throwing exceptions | Calling another code snippet in another activity. |
Data Types
All system and application data types are supported. Importing namespaces is performed by using the namespace import functionality within a workflow definition or subprocess. The imported namespaces apply to all Code activities in the workflow or subprocess after they have been added. Further to this, Workflow allows you to add references from other assemblies.
Parameters
The Code activity parameters consist of subprocess and workflow parameters that have already been configured. To use elements of the workflow (for example, parameters, local variables, activity properties, and so on) in your code snippet, you must add a parameter and link it to the desired data. Changes to a parameter's value are reflected in the workflow after the code has been executed. For example, the parameters are 'ref' or 'InOut'.
Example Code Snippet
In this example, there are subprocess parameters called Field1 and Field2. In the Code activity configuration, Field1 will be bound to the parameter called InitialValue. Field2 will be bound to a parameter called AdjustedValue.
AdjustedValue = InitialValue * 2 + 40;
If (AdjustedValue > 100) Then
AdjustedValue = 100
End If
Upon running this script in an instance of a workflow, Field2 will be set to the value of AdjustedValue.