Workflow Manager 1.0 Configuration and External Variables


Updated: July 12, 2012

Workflow Manager 1.0 provides the capability of setting configuration values to be used during execution, enabling common and well established best practices when modeling processes such as avoiding hard coding parameters that may change within a program definition (in this case, a workflow). Workflow application authors can set application settings associated with a workflow definition. These application settings are a list of key-value pairs and are similar in concept to .NET AppSettings. This list can contain any set of keys and values to represent relevant information for your workflow.

Setting Configuration

Configuration application settings are established at the workflow definition level via WorkflowDescription.Configuration. The code below demonstrates an example of how to set application settings (by adding items to the AppSettings collection of WorkflowConfiguration).

sampleConfigValueWorkflow.Configuration = new WorkflowConfiguration();  
sampleConfigValueWorkflow.Configuration.AppSettings.Add("configSetting1", "configuration value");        
sampleConfigValueWorkflow.Configuration.AppSettings.Add("anotherConfigSetting", "another value");  

System_CAPS_ICON_note.jpg Note

WorkflowConfiguration provides other configuration settings that are not directly usable from the programming model in WF such as throttling options.

A default workflow configuration can be set to all the workflows in a given scope by setting a WorkflowConfiguration object to ScopeInfo.DefaultWorkflowConfiguration. When this default configuration is set all the WorkflowDefinitions in the scope will use those configuration settings. WorkflowDefinitions can override them by providing their own WorkflowConfiguration.

Using Configuration Information in a Workflow

The GetConfigurationValue activity enables workflow authors to consume Application Settings from configuration for a given workflow. GetConfigurationValue accepts the name of the application setting and an output variable where to store the application setting. It also accepts an optional default value that is the value that will be assigned to the output variable in case that the requested application setting is not found. The workflow in the following screenshot demonstrates a GetConfigurationActivity that uses the configSetting1 setting specified in the previous example.

Workflow Configuration Activity Properties

ExternalVariables and UserStatus

ExternalVariables allow workflow authors to model global state within a workflow. ExternalVariables are added to a WorkflowDefinition using the ExternalVariables property, and are visible to all activities within that workflow. This means that these variables are going to be visible to all implementation children of the workflow, including the implementation of the custom activities used in it. ExternalVariables can be of any type allowed within workflows (types in the allowed types list).

System_CAPS_ICON_note.jpg Note

For more information about allowed types, see Trusted Surface.

ExternalVariables can be mapped. This means that when the workflow is persisted they can be accessed using WorkflowInstanceInfo.MappedVariables. If an ExternalVariable is not marked as mapped, it will be saved as part of the instance state but will not be accessible using WorkflowInstanceInfo.

ExternalVariable values are accessed using ExternalVariableValue<T> activity. In order to set the value of an ExternalVariable, ExternalVariableReference<T> is used as an L-Value (for example in Assign).

System_CAPS_ICON_note.jpg Note

ExternalVariableValue<T> is supported in the workflow designer, but currently ExternalVariableReference<T> is only supported in code.

Workflow Manager 1.0 also introduces a first-class mapped ExternalVariable named UserStatus (accessed using the UserStatus property) and an activity to set it from the workflow called SetUserStatus. This provides a simple start-up experience for using ExternalVariables in the most common case where only a single ExternalVariable is needed.

ExternalVariables vs. Configuration

The following table compares the features of Workflow Configuration and ExternalVariables.

GranularityDefinition or higher (e.g. Scope)Instance
Allowed TypesStringAny type in the allowed types list
Can be changed by workflow instanceNoYes
Activity SurfaceGetConfigurationValueExternalVariablesValue<T>

Can be mappedNoYes

Community Additions