Working with XAF CRUD activities–Introduction

XAF Team Blog
01 June 2011

In this post we are going to explore the built in XAF CRUD activities beginning with how a workflow execution takes place.

The workflow server acts as a host for WorkflowServiceHost objects and a number of services. Services will perform every action needed in a very decoupled way. For example, there is a service that will read WorkFlowDefinitions, another that creates and starts a WorkflowServiceHost for each definition, another that will search for objects that match the WorkflowDefintions’ criteria and so on. Every 15 seconds the later service runs and if objects found it calls the service that can start the corresponding workflow. Note that only one workflow instance can be started for each found object. The following image is an Issue workflow definition taken from our Workflow demo. It will run for all Issues whose Active property is true.

image

However in the above image we see that Object Fits Criteria is not checked meaning that  this WorkFlowDefintion doesn’t provide StartWorkFlowConditions therefore this workflow will not start. In addition we can check Object Is Created and force the workflow to run instantly when a new Issue is created rather than after 15 sec. Moreover if a WorkFlowDefintion is not active will not start. You can activate a WorkFlowDefintion by executing the Activate action (next to refresh).

When working with workflows and persistent objects it is better to keep transactions short. For example, when reading data from a database, checking values, modifying, creating, deleting, committing changes and completing transactions. It is better to avoid continuous operations in the ObjectSpaceTransactionScope, because we are inside an XPO transaction. Since this is an atomic operation, workflow can not be persisted while workflow is inside the ObjectSpaceTransactionScope. If there is a need to use delays, especially within loops, consider placing them outside XAF’s container activities (NoPersistScope,ObjectSpaceTransactionScope).

Next we are going to examine how to create a workflow from scratch using the demo . The scenario is, creating a new Task when an active Issue is found and setting its subject by concatenating a fixed string with the issue subject.

image

Since we are going to create a new persistent object (Task) we have to use an ObjectSpaceTransactionScope as a container for our activities. After we create a new WorkflowDefinition a new 'targetObjectId' argument will automatically be created for it. We need to manage arguments only when we are creating a reused workflow definition and planning to call it manually. We have to leave the 'targetObjectId' argument unchanged if WorkflowDefinition instances will be started by the WorkflowServer.

image

The next step is to find the active Issue using the targetObjectId value and assign it as  Key to a GetObjectByKey activity.

image

However the Issue is being queried because we need to assign its subject to a Task object that will be create later. For this reason we need to define a variable that can hold it.

image

Variables in workflows are very much like the variables we are used to in imperative languages. They describe a named location for data to be stored and they follow certain scoping rules. Since we need the issue variable to be accessible from all activities inside the ObjectSpaceTransactionScope, we use this value in the Scope column.

The next step is to create the new Task object. Later the resultant Task will be used by other activities so we also need to create a variable to hold it.

image

In the final step we are going to use both ObjectSpaceTransactionScope variables - issue and task as defined in previous steps. A native WF Assign activity is dropped into the designer and uses to set the Task’s subject to an expression.

image

There is no need to commit the XPO transaction because by default, the ObjectSpaceTransactionScope activity commits all the changes at the end. However it is possible to control this behaviour by setting the AutoCommit attribute to false.

image

 

In the next post we are going to talk about “short transactions” inside a long running workflow and how to debug it.

Please free to ask any questions you might have and as always happy XAFing!

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.