User Guide: Workflow > Workflow Best Practices
Workflow Best Practices
Use Case: Workflows are executed in the background. In case of long-running workflows, if you are using attributes from an identity scope or session scope, there is no guarantee that those attributes are available throughout the workflow execution.
Recommended best practices: When a workflow needs any kind of attributes from an IDENTITY or SESSION scope, always try to populate the necessary data from all other scopes to FOUNDRY_WORKFLOW_CONTEXT, and use these values from FOUNDRY_WORKFLOW_CONTEXT.
You can configure the attributes from an IDENTITY or SESSION scope by using Process Incoming Payload mapping editor or a service task.
How to Store namespace data in FABRIC_WORKFLOW_CONTEXT using Process Incoming Payload (User Task in Fabric Console)
-
Click Configure under *Process Incoming Payload of a in User task properties, in a workflow service. The Process Incoming Payload* dialog box appears.
(Resources/Images/UserTaskOP1.png)- Specify a top-level key name in FOUNDRY_WORKFLOW_CONTEXT field. The top-level key stores data copied from output elements of the other namespaces.
-
Map parameters in the table to copy data from other namespaces. Individual elements of the output can be accessed by using a dot(.) notation with a key.
For example,
Foundry_Workflow_Context.UserTaskKey1.applicationId = Device_request.applicationId- Top-level key:
UserTaskKey1, which stores data copied from the mapped output of the element,applicationId. - The
applicationIdelement is mapped to theapplicationIdparameter that is available in the DEVICE_REQUEST namespace.
- Top-level key:
How to Store namespace (identity or session) attributes as key value by using a service task
- Avoid using the
IDENTITYscope as it can expire at any time while the workflow is under execution. Instead, populate the necessary values from anIDENTITYscope to FOUNDRY_WORKFLOW_CONTEXT by using a service task. - Avoid using the
SESSIONscope as it can contain custom data elements that might get lost while persisting when a workflow execution fails. Instead, populate the necessary values from aSESSIONscope to FOUNDRY_WORKFLOW_CONTEXT by using a service task.
Though an attempt will be made for persisting the session scope data on workflow failure, but it is not fully guaranteed.