rules.json Syntax

This page describes the JSON syntax for defining rule objects used in template-to-app-rules.json and app-to-template-rules.json. For background on how rules fit into the App Template Framework, see Work with App Template Framework Rules.

The rules object can contain any number of rule objects. A rule object is made up of:

AttributeTypeExampleRequiredNotes
nameString"name": "ruleName"YesAn identifier for the rule.
conditionString"condition": "${Variables.foo == 'Yes'}"NoUse Freemarker conditions to apply the rules. Use the same syntax as conditions used in template-info.json.
appliesToArray"appliesTo": [{"type": "dashboard", "name": "*"}]YesUse "type": "*" to apply to all JSON assets. Other valid values are dashboard, lens, workflow, schema, and xmd. Use the name string to reference specific JSON assets. The name can take * as well, to apply to all of one asset type or a group of one asset type.
descriptionString"description": "This rule adds strings to an array."NoUse this to explain what the rule is doing.
actionsArray"action": "set"YesThere are six supported action types: add, put, set, delete, eval, and replace. Define as many actions as needed in the array.

Rule Example with appliesTo Value 

1{
2    "name": "myRuleForWorkflowNodeDelete",
3    "appliesTo": [
4      {
5        "type": "workflow",
6        "name": "*"
7      }
8    ],
9    "actions": [
10      {
11        "action": "delete",
12        "description": "delete node from workflow",
13        "path": "$.workflowDefinition.nodeName"
14      }
15    ]
16}

Actions Syntax for Rules 

ActionNotes
addAdds an entry to an existing array. Needs index and value. index is 0 for the first element in the array, any number after that for the middle of the array. If index is larger than the array size, this action adds the value to the end of the array.
putAdd an attribute and value to an existing JSON value. Needs key and value. value can be a string or an array.
setSet a value on an existing JSON attribute. Needs value.
deleteRemove a node in the existing JSON tree.
evalEvaluate the expression specified in value and assign results to the context variable specified by key (if set). Context attribute can be referenced using the expression: ${Rules.Eval.<variable_name>}. The scope of the eval variable is the entire document if performed in a rule, or the macro if performed within a macro.
replaceReplace any text string throughout the entire document. Use when regular expressions are not an option. Can still use expressions. Instead of using the replace action, you can perform targeted search and replace (JSON Path) with ${string:replace(...)}. In cases requiring regular expressions, use ${string:replaceFirst(...)}, ${string:replaceAll(...)}.

Example add Action 

1{ 
2    "action": "add",
3    "description" : "Add desc",
4    "path": "$.json.path.to.existing.json,array",
5    "index": 0,
6    "value": "value to add"
7}

Example put Action 

1{ 
2    "action": "put",
3    "description" : "Put desc",
4    "path": "$.json.path.to.existing.json",
5    "key": "jsonAttributeName",
6    "value": "new value"
7}

Example set Action 

1{ 
2    "action": "set",
3    "description" : "Set desc",
4    "path": "$.json.path.to.attribute",
5    "value": "setValue"
6}

Example delete Action 

1{ 
2    "action": "delete",
3    "description" : "Delete desc",
4    "path": "$.json.path.to.delete"
5}

Example eval Action 

The eval action retrieves the sayHello macro result and then the set action uses the result to set a value in a JSON path.

1[
2    {
3        "action": "eval",
4        "description": "Evaluate the sayHello macro",
5        "key": "helloResult",
6        "value": "${myMacros:sayHello('Hello')}"
7    },
8    {
9        "action": "set",
10        "path": "$.path.json.node",
11        "value": "${Rules.Eval.helloResult}"
12    }
13]

Example replace Action 

1{
2    "action": "replace",
3    "description": "Replace the amount field value",
4    "key": "RPLCM_Opportunity_Amount_Field",
5    "value": "${Variables.Opportunity_Amount.fieldName}"
6}

See Also