Define Variable Action
This type of action allows to initialize or update some variable that will be available in the whole process context. This variable can be used somewhere in the subsequent steps/connectors.
The Action when it is being added offers several settings, depending on the main one - the "Variable type" (1):
Variable can be one of 4 types:
- Text
- Query
- Apex
- JSON
Text
Variable will have a string data type. It requires Name (2) property. Value (3) is optional (it will be equal to empty string).
Name can be specified as regular text or can be set dynamically. You can use Variables, Merge Fields to set the name.
Query
Actually it is the way to specify several variables together based on Data Source Objects record fields.
- Select Query variable type, choose object (4) which fields will be used to set values to variables
- Click "Add field" button on Fields section (5):
- Choose Field name (6) and set new Variable name (7):
- Add condition if necessary: click "Add Condition" button (8) and specify Name, Operator and Value:
NOTE: For more information about using conditions check following article: Using Query Conditions.
Apex
The value of variable(s) will be calculated by some program code.
- Select Behavior (9) to define if only one variable will be returned or several:
Single Variable will define one variable
Multiple Variables will define a number of variables: In case of 'Multiple Variables' the apex class must return the variables string in JSON format.
- Provide variable name and class name (10, 11).
NOTE: To use this kind of variables you need to have apex class implementing WorkflowDefineVariableActionInterface
interface.
Example of an apex class that will set variable value:
public with sharing class callApexWrapper implements WR_BPM.WorkflowDefineVariableActionInterface {
public Object execute(sObject context,WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor,String operationType,String parameters) {
Object result = '';
if(parameters == '4')
result = 'Hello world';
return result;
}
}
Execute method sets variable based on parameters value - if it equals '4' variable value would be 'Hello world', if not it will be left blank.
NOTE: result could be of any type that can be converted to String.
Example of the text method that can be used to test example class:
@isTest static void executeTest(){
Account accountRecord;
WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor;
CallApexWrapper cont = new CallApexWrapper();
Object result = cont.execute(accountRecord, flowInstanceCursor, '', '4');
System.assert(result == 'Hello World');
}
- Specify necessary parameters (12). E.g., switch to Advanced mode, choose Context object, choose Context object item:
NOTE: In the above example variable value will be set to 'Hello world' as step name passed as a parameter to an apex class is '4'.
JSON
Select JSON variable type, provide coma separated Names and Values:
Use JSON format to enter any number of variables:
Example:
{"AccountSource": "{Account.AccountSource}", "AccountName":"{Account.Name}"}
{$Variables.AccountSource}
will return Account.AccountSource value.
How to work with Action Results
Variables defined in this Action are available to work in these places:
- On the Global Action Group: as usual variable that are available for any action in this group (if these are new variables, they will be created otherwise they will be updated).
- On the Form: as fields of special Output context object.
How to work with Output context object:
E.g., user has an action that defines some variables:
This action returns it's results and user needs to use it in some other action, e.g., in the form. User can specify a Result Handler for current "Define Variable" action and Output context object will be available to select (12). When it is selected, system will suggest names of variables defined by that action (13). And when selected, an Output Variable will be available to use as merge field $Output.variableName
(14):
This merge field can be used as a value of some parameter of result handler.
0 Comments
Add your comment