Structuring and Organizing Rules

The rules section of template-to-app-rules.json defines the rules followed by the template.

The section is made up of three parts:

  • Action: Designates the operation to perform.
  • Path: Defines the path to the location where the action is performed.
  • AppliesTo: Determines the asset files to apply the rules to. Consists of a name.

Rules can be divided into multiple files, which are executed in the order in which you list them in template-info.json. Be sure that a rule that runs first doesn’t refer to a constant referenced in a rule that runs later.

Here are a few guidelines to consider when working with multiple rules files:

  • One rules file can contain all constants, another all actions.
  • Use multiple rules when actions grow to 500 lines. You could divide them into a rules file for dashboards, another for datasets or the dataflow.
  • If you have content to be used by many rules, include it in the first rules file to be executed.

Here is a simple example, a rule for changing the title text on a dashboard:

1{
2    "name": "Update dashboard title",
3    "appliesTo": [
4        {
5            "type": "dashboard",
6            "name": "DashboardOne"
7        }
8    ],
9    "actions": [
10        {
11            "action": "set",
12            "description": "change the title text of the dashboard",
13            "path": "$.state.widgets.title_text.parameters.text",
14            "value": "${Variables.DashboardTitle}"
15        }
16    ]
17}

Make rules more powerful using functions. See Use Functions in Rules.