Set a variable
You can use the Set Variable step to set value of a variable and define the order in which the values are set. The variable is set in the order the variable mappings are listed in the set variable step.
Changes to variable values affect only the instance of the process in which the change occurs. For example, when a workflow is initiated and variable data changes, the changes affect only that instance of the workflow. The changes do not affect other instances of the workflow that were initiated previously or are initiated subsequently.
Depending on the data type of the variable, you can use the following options to set value of a variable:
-
Literal: Use the option when you know the exact value to specify.
-
Expression: Use the option when the value to use is calculated based on an expression. The expression is created in provided expression editor.
-
JSON Dot Notation: Use the option to retrieve a value from a JSON or FDM type variable.
-
XPATH: Use the option to retrieve a value from an XML type variable.
-
Relative to payload: Use the option when the value to be saved to variable is available at a path relative to payload.
-
Absolute path: Use the option when the value to be saved to variable is available at an absolute path.
You can also update specific elements of a JSON or XML type variable using JSON DOT Notation or XPATH notation.
Go To step
The Goto Step lets you specify the next step in the workflow model to execute, dependent on the result of a routing expression.
Similar to the OR Split step, you can define routing expression for Goto step using a rule definition, ECMA script, or an external script.
You can use variables to define the routing expression using the expression editor. For more information on using routing expressions for the Goto step, see Goto Step.
In this example, the Goto step specifies the Review Credit Card Application as the next step if the value for the actiontaken variable is equal to Need more info.
For more examples on using rule definition in the Goto step, see Simulating a For loop.
Forms-workflow centric workflow steps
All AEM Forms Workflow steps support variables. For more information, see Forms-centric workflow on OSGi.
Workflow steps without support for variables
You can use MetaDataMap interface to access variables in workflow steps that do not support variables.
Retrieve the variable value
Use the following APIs in the ECMA Script to retrieve values for existing variables based on the data type:
Variable data type | API |
---|---|
Primitive (Long, Double, Boolean, Date, and String) | workItem.getWorkflowData().getMetaDataMap().get(variableName, type) |
Document | Packages.com.adobe.aemfd.docmanager.Document doc = workItem.getWorkflowData().getMetaDataMap().get(“docVar”, Packages.com.adobe.aemfd.docmanager.Document.class); |
XML | Packages.org.w3c.dom.Document xmlObject = workItem.getWorkflowData().getMetaDataMap().get(variableName, Packages.org.w3c.dom.Document.class); |
Form Data Model | Packages.com.adobe.aem.dermis.api.FormDataModelInstance fdmObject = workItem.getWorkflowData().getMetaDataMap().get(variableName, Packages.com.adobe.aem.dermis.api.FormDataModelInstance.class); |
JSON | Packages.com.google.gson.JsonObject jsonObject = workItem.getWorkflowData().getMetaDataMap().get(variableName, Packages.com.google.gson.JsonObject.class); |
You require AEM Forms add-on package for Document and Form Data Model variable data types.
Example
Retrieve the value of string data type using the following API:
workItem.getWorkflowData().getMetaDataMap().get(accname, Packages.java.lang.String)
Update the variable value
Use the following API in the ECMA Script to update the value of a variable:
workItem.getWorkflowData().getMetaDataMap().put(variableName, value)
Example
workItem.getWorkflowData().getMetaDataMap().put(salary, 50000)
updates the value for the salary variable to 50000.
Set variables to invoke workflows
You can use an API to set variables and pass them to invoke workflow instances.
workflowSession.startWorkflow uses model, wfData, and metaData as arguments. Use MetaDataMap to set value for the variable.
In this API, the variableName variable is set to value using metaData.put(variableName, value);
import com.adobe.granite.workflow.model.WorkflowModel;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.aemfd.docmanager.Document;
/*Assume that you already have a workflowSession and modelId along with the payloadType and payload*/
WorkflowData wfData = workflowSession.newWorkflowData(payloadType, payload);
MetaDataMap metaData = wfData.getMetaDataMap();
metaData.put(variableName, value); //Create a variable "variableName" in your workflow model
WorkflowModel model = workflowSession.getModel(modelId);
workflowSession.startWorkflow(model, wfData, metaData);
Example
Initialize the doc document object to a path (“a/b/c”) and set the value of the docVar variable to the path stored in the document object.
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.model.WorkflowModel;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.aemfd.docmanager.Document;
/*This example assumes that you already have a workflowSession and modelId along with the payloadType and payload */
WorkflowData wfData = workflowSession.newWorkflowData(payloadType, payload);
MetaDataMap metaData = wfData.getMetaDataMap();
Document doc = new Document("/a/b/c");// initialize a document object
metaData.put("docVar",doc); //Assuming that you have created a variable "docVar" of type Document in your workflow model
WorkflowModel model = workflowSession.getModel(modelId);
workflowSession.startWorkflow(model, wfData, metaData);
Store sensitive user data outside JCR using workflow variables
Data processed using Forms Workflow can contain sensitive user data, such as Personally Identifiable Information and Sensitive Personal Information. Businesses can choose to store the data, that is processed by various workflow steps (and passed using workflow variables), out of JCR storage into an external data store owned and managed by them. To know more about persisting workflow data in an external storage, see Using workflow variables for customer owned datastores.
Adobe Experience Manager provides Workflow API UserMetaDataPersistenceProvider to store workflow variables in external Azure blob storages. For details about using the API, see Use workflow variables to parameterize sensitive data and store in external data stores.
Edit a variable
- On the edit workflow page, select the Variables icon available in the sidekick of the workflow model. The Variables section in the left pane displays all existing variables.
- Select the
- Edit the variable information and select
Delete a variable
Before deleting the variable, remove all the references of the variable from the workflow. Ensure that the variable is not used in the workflow.
Execute the following steps to delete a variable:
- On the edit workflow page, select the Variables icon available in the sidekick of the workflow model. The Variables section in the left pane displays all existing variables.
- Select the Delete icon next to the variable name that you want to delete.
- Select
References
For more examples on using variables in AEM Forms Workflow steps, see Variables in AEM workflows.
Experience Manager
Espressos & Experience Manager: AEM Forms
Espressos & Experience Manager
Thursday, Mar 6, 7:00 PM UTC
Join Adobe's AEM product team as they highlight AEM Forms' latest innovations, including: the new Gen AI Assistant, Unified Composition with AEM Sites, and new ways to deploy forms through conversations.
RegisterAdobe Experience Manager Forms at Summit
Register for these sessions:
- Elevate and Empower Teams with Agentic AI for Exceptional Experiences (attend online)
- The Future of Forms: Experience Success Across the Enrollment Journey (attend online)
- The True Cost of a Failed Implementation (attend online)
- Driving Marketing Agility and Scale: Transforming your Content Supply Chain with AI (attend online)
- Put the Customer at the Center and Build Relationships That Last a Lifetime (attend online)
Connect with Experience League at Summit!
Get front-row access to top sessions, hands-on activities, and networking—wherever you are!
Learn more