Rules files define how an app gets created by the template.
There are two type of rules files: template-to-app-rules.json and app-to-template-rules.json. They use the same syntax, but serve different purposes.
template-to-app-rules.jsondefines the rules that the template follows when creating an app. For example, you can define a rule that specifies that if an org doesn’t use certain objects, the app doesn't use them in dashboards or the dataflow. Another rule can replace a label name in a chart with the name of a field from a Salesforce object selected in a wizard question. Rules also define how variables are handled. For example, if the wizard asks which fields to include in filters for accounts,template-to-app-rules.jsondetermines how that choice is reflected in dashboards.app-to-template-rules.jsonprovides rules for converting an updated source app back to template form. After changing the source app, you update the template object with a PUT call to the CRM Analytics REST API. For example, you can tokenize all asset files every time they are pulled out of the source app. You use app-to-template rules infrequently, because you're unlikely to update the source app often.
The rules file is referenced from template-info.json:
"rules" : [
{ "type" : "appToTemplate", "file" : "appToTemplateRules.json" },
{ "type" : "templateToApp", "file" : "templateToAppRules.json" }
],
The bulk of what follows details the use of template-to-app-rules.json.
-
Rules files can contain three sections: rules, constants, and macros.
-
Structuring and Organizing Rules
The rules section of
template-to-app-rules.jsondefines the rules followed by the template. -
The rules object may contain any number of rule objects. A rule object is made up of:
-
Actions define what a rule does. Use constants to make it easier to perform any action.
-
Functions make rules more powerful. For example, use functions to apply rules iteratively to arrays or to make rules conditional on the content of a string or an array. CRM Analytics Templates supports string, array, and json functions as well as static math and sfdc_fma functions.
-
Use a macro when a single rule executes repeatedly on different JSON node paths.
See Also