---
schema_version: "1"
id: 13e4bfc3f4cd830e39e876c3b9ce706ad05476029e10a459c918de794316ffd1
title: Macro Examples
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_wave_templates/guides/concept/bi-templates-dev-macro-examples.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templates-dev-macro-examples.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: cbbc7a1d4b2edc73011d150f3fae5c3a8f1b382e08cb43a6023e37cd8c0c9fe5
products:
  - Analytics Templates Developer Guide
  - analytics
---

# Macro Examples

The following examples show the structure and syntax of macros in rules.

Here’s an example macro showing the use of attributes, parameters, and `“path”` statements.

```nolang
"macros":
 [ 
        { 
            "namespace": "myMacroNamespace",
             "definitions": [ 
                { 
                    "name": "multiplyTwoNumbers",
                     "parameters": [ 
                        "firstNumber",
                         "secondNumber" 
                    ],
                     "returns": "${p.firstNumber * p.secondNumber}" 
                },
                  { 
                    "name": "deleteWidget",
                     "description": "Deletes a widget and any references to the widget.",
                     "parameters": [ 
                        "widgetName" 
                    ],
                     "actions": [ 
                        { 
                            "action": "eval",
                             "key": "results",
                             "path": "${json:searchPaths(\”$.state.widget['p.widgetName']\”)}” 
                       },
                          { 
                            "condition": "${!empty results}",
                             "action": "delete",
                             "path": "$.state.widgets['${p.widgetName}']" 
                        },
                          { 
                            "condition": "${!empty results}",
                             "action": "delete",
                             "path": "$.state.gridLayouts..pages..widgets[?(@.name=='${p.widgetName}')]" 
                        } 
                    ] 
                } 
            ] 
        } 
    ],
      "constants": [...],
      "rules": [...] }

```

The following example calls a macro with namespace `'myNS'` and macro name `'getSomething'` defined with no parameters. Results of the macro are stored in the template context, and can be referenced using this expression: `${Rules.Eval.macroResults}`.

```nolang
{
  "action": "eval",
  "key": "macroResults",
  "value": "${myNS:getSomething()}"
}
```

This example sets the JSON node at path \$.path.to.json.node with the result of macro `myNS:getJsonValue` defined with no parameters. This action will only be called if the macro `myNS:shouldExecute` (defined with one parameter) returns true.

```nolang
{
  "action": "set",
  "condition": "${myNS:shouldExecute(true)}",
  "path": "$.path.to.json.node",
  "value": "${myNS:getJsonValue()}"
}
```
