The Set Values action sets values in the data JSON of an Integration Procedure using literal values, merge fields, or formulas.
Any text between two percent (%) signs in a Set Values formula is treated as a merge field. To represent literal percent (%) signs, use the
$Vlocity.Percent
environment variable.
The Set Values action doesn’t support custom labels.
Properties
|
Property |
Description |
|---|---|
|
Element Value Map: Element Name |
The JSON node for which the value is to be set. |
|
Element Value Map: Value |
The value to assign to the JSON node. Options:
|
Examples
For the following examples, consider this sample input JSON.
{
"Name": {
"FirstName": "John",
"LastName": "Smith"
},
"Finances": {
"GrossIncome": "100000",
"Expenses": "60000"
}
}
Rename Nodes in the Input Data
To shorten and simplify the input JSON nodes, set the Element Value Map like this example.
|
Element Name |
Value |
|---|---|
|
FirstName |
%Name:FirstName% |
|
LastName |
%Name:LastName% |
|
GrossIncome |
%Finances:GrossIncome% |
|
Expenses |
%Finances:Expenses% |
Set Literal Values
To set literal values, which are useful for testing or for specifying data that doesn't change, set the Element Value Map like this example.
|
Element Name |
Value |
|---|---|
|
Location |
San Francisco |
|
Code |
2345 |
Concatenate Literal Values and Merge Fields
To concatenate a literal string with a merge field, set the Element Value Map like this example.
|
Element Name |
Value |
|---|---|
|
LocationCode |
Code is %LocationData:Code% |
The %LocationData:Code% merge field retrieves data from the previous
component, LocationData.
Define an Array
To set up an array, click Edit as JSON and edit the
ElementValueMap node like this example.
"elementValueMap": {
"Departments": [
"Sales",
"Development",
"Support",
"Training"
]
},
Perform Simple Calculations Using Formulas
To perform calculations, use operators in the the Element Value Map like these examples.
|
Element Name |
Value |
|---|---|
|
AfterTaxIncome |
=%Inputs:GrossIncome% * 0.7 |
Set the Element Value Map of CalculateNet as follows:
|
Element Name |
Value |
|---|---|
|
NetIncome |
=%AfterTax:AfterTaxIncome% - %Inputs:Expenses% |
Concatenate Two Merge Fields
To concatenate two merge fields, set the Element Value Map like this example.
|
Element Name |
Value |
|---|---|
|
FullName |
=%Inputs:FirstName% + " " + %Inputs:LastName% |
Notice the literal space included to separate the first and last names.
Use a Function and Retrieve an Array Value
This example uses the IF function. It also uses listnode|listnumber notation
to retrieve array values.
|
Element Name |
Value |
|---|---|
|
Department |
=IF(%Inputs:FirstName% = "John",%DeptArray:Departments|2%,%DeptArray:Departments|3%) |
This component assigns a Department value of Development to anyone named John and a Department value of Support to anyone not named John. Notice that the second equals sign has spaces before and after it, to distinguish it from the function.
Perform a Complex Date Calculation
This example uses four nested date functions to return the first day of the current month.
|
Element Name |
Value |
|---|---|
|
FirstOfThisMonth |
=ADDDAY(EOM(ADDMONTH(TODAY(),-1)),1) |
Create a Structure for Output Data
This example creates a JSON structure for the transformed data. To set up the structure,
click Edit as JSON and edit the ElementValueMap node
like this sample JSON.
"elementValueMap": {
"Output": {
"FullName": "%ConcatName:FullName%",
"Department": "%RetrieveDept:Department%",
"AfterTaxIncome": "%AfterTax:AfterTaxIncome%",
"NetIncome": "%CalculateNet:NetIncome%",
"Location": "%LocationData:Location%",
"LocationCode": "%TextWithCode:LocationCode%",
"FirstOfThisMonth": "%CalcFirstOfThisMonth:FirstOfThisMonth%"
}
},