A workflow is a list of activities to execute. There are several GN4 activities that you can use to perform operations in GN4 system (like reading GN4 objects from database, sending emails, creating new GN4 objects, publishing, etc…).
The CodeWorkflow activities are .NET classes, so you have to instantiate them into the VB.NET code before using them. Let’s see how.
In the following example, we want to load the xml of a GN4 object, given its id.
Dim imgId As Integer = 12345
Dim loadImgAct As LoadObjects = New LoadObjects(Context) With {.Name = "load picture", .Description = "loading image..."}
loadImgAct.ObjectIds.Add(imgId)
Dim loadImgRes As LoadObjectsResult = loadImgAct.Do()
Dim objectXml As XDocument = loadImgRes.XmlOut
1.First, we create a new activity object (of type LoadObjects, called ‘loadImgAct’):
Dim loadImgAct As LoadObjects = New LoadObjects(Context) With {.Name = "load picture", .Description = "loading image..."}
Notes
•All the CodeWorkflow activities receive the ExecutionContext object (called ‘Context’) as parameter. This object contains the values passed to the workflow (Pars, ObjectIds, Data, etc…); it is analogous to the root activity (often called ‘mainWorkflow’) of the old WindowsWorkflows.
•Every CodeWorkflow activity object has the Name property, but (unlike the old WindowsWorkflows) it is not used anymore to associate the resource xml to the activity, but only in progress reports and error reporting. In this example, loadImgAct.Name = “load picture”.
•Another property of the CodeWorkflow activity object is Description and it is used in the progress report to display which activity is being executed.
•In the standard CodeWorkflows, the name of the activity objects ends with the “…Act” suffix, to easily identify the variable as GN4 activity into the code)
2.Then, we set the input data (in this example, the id of the object to look for):
loadImgAct.ObjectIds.Add(imgId)
In CodeWorkflows, all the data needed in input by the activity are properties of the activity object. In this example, the loadImgAct.ObjectIds property is a list of integers, so we can simply add as number the id of the GN4 object to look for.
3.Execute the activity
Dim loadImgRes As LoadObjectsResult = loadImgAct.Do()
To execute a code activity you must call its Do() method. The Do() method returns the output data into a result object. Note that every activity type as a corresponding …Result class which contains the operation results: the LoadObject activity returns the read xml into a LoadObjectsResult object, the TransformXml activity returns the transformed xml into a TransformXmlResult object, and so on.
4.Read the operation results:
Dim objectXml As XDocument = loadImgRes.XmlOut
In general, every code activity receives data in input, performs an operation and returns the output results. The data in input are the properties of the activity object (like loadImgAct.ObjectIds); the output results are the properties of the result object (like loadImgRes.XmlOut).
Note that in the standard CodeWorkflows, the name of the result object ends with the “…Res” suffix, to easily identify the variable as output objects into the code.
All the significant activities of the old WindowsWorkflows have been ported to the new CodeWorkflows, keeping the same names.
There are some important exceptions:
•The old Variant activity becomes “Variation” (because “variant” is a reserved VB.NET keyword).
•The old XAML activities that manage data lists (DataOp, IdsOp, …) were not ported in code workflows, because VB.NET can manage lists much better.
•The replicator activities (DataReplicator, ObjectsReplicator, …) were not ported in code workflows, because VB.NET can manage looping much better (For Each, Do While, etc…).
The execution Context object
Every activity must receive the Context object into its constructor.
Dim loadImgAct As LoadObjects = New LoadObjects(Context) With {.Name = "load picture"}
The Context object contains all the workflow parameters and has some useful properties and methods:
•ExecutionLog property
It is a xml variable, which is used in some standard workflow to contain xml data needed by GN4 to work. For example, the importWF workflows of the Feed Data Source in Back4 receive the data to process in the Context.ExecutionLog variable. In custom code workflows, it can be used to store xml data when needed.
•XsltExtensions object
It allows to use the GN4 XSLT extension methods in code workflows, such as objectIdFromString(), trimText(), pathFileName(), etc…
See http://tech.teradp.com/tech/html/gn4/docs/VSdoc/frlrfTeraDPGN4CommonXsltExtensionsClassTopic_members--.html for more information about the XSLT extensions of GN4.
•CreateActivityData static method
It creates a file object (IActivityData) from a string and it can be useful to save a string value into a file.