Define Variable Action

Define Variable allows to create Variables which can be used inside the Action Group or passed as an output other parts.

  • Add an action with the type Define Variable (1).

  • Variable can be of 4 types (2):

    • Text,

    • Query,

    • Apex

    • JSON

Variable will have a string data type. It requires Name (3) property. Value (4) 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.

Actually it is the way to specify several variables together based on Data Source Objects record fields.

  • Select Query variable type, choose object (5) which fields will be used to set values to variables

  • Click "Add field" button on Fields section (6):

  • Choose Field name (7) and set new Variable name (8):

  • Add condition if necessary: click "Add Condition" button (9) and specify Name, Operator and Value:

NOTE: For more information about using conditions check following article: Working with Conditions

Apex

The value of variable(s) will be calculated by some program code.

  • Select Behavior (10) 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 KanBanInterfaces.DefineVariableActionInterface interface.

Below is an example of an apex class that will set variable value

public with sharing class CallApexWrapper implements FLX_KB.KanBanInterfaces.DefineVariableActionInterface {   
    public Object executeDefineVariable(FlX_KB.KanBan_History__c history, sObject record, Object 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

Below is example of the text method that can be used to test example class

@isTest static void executeTest(){
   CallApexWrapper cont = new CallApexWrapper();
   Object result = cont.executeDefineVariable(null, null, '4');
   System.assert(result == 'Hello World');
} 

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

Save the action. Now you can call it from Kanban and other places.

How to Work With Action Results

Variables defined in this Action are available to work in these places:

  • On the Kanban: as usual kanban variables (if these are new variables, they will be created otherwise they will be updated). They can be checked in kanban debug console.

  • 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 (11):

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.

Last updated