# Effects Autocomplete

### **What It Does**

Open Loyalty provides powerful autocomplete support when building campaign formulas—whether for calculating rewards, setting pending or expiration dates, or referencing balances. You can access both **templates** (common formulas) and **variables** (context-specific data) through dropdown suggestions.

***

### 🧰 Overview

* The dropdown appears when you click into any formula field (e.g., *Add units*, *Expiration date*, *Pending units*).
* It’s divided into **Templates** (pre-defined formula snippets) and **Variables** (data fields you can insert).

***

### 🔄 Trigger‑Specific Variables

{% hint style="success" %}
The list below is not complete - it is supposed to give you an overview of the available options.
{% endhint %}

Depending on the campaign trigger you chose, the dropdown will surface different context variables:

**For Purchase or Return campaigns:**

* `transaction.grossValue` – total value of the entire purchase/return
* `transaction.qty` – total item count
* **Item-level filters** create expressions like:
  * `transaction.sku('ABC123').qty` or `.grossValue`
  * `transaction.category('Beverage').grossValue`
  * `transaction.maker('BrandX').qty`

These allow precise designs such as “Give 10 points for each specific SKU purchased” or “Deduct units only for returns above $100 worth of electronics.”

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FrpgcS6NljpVnlciuQhTc%2Fimage.png?alt=media&#x26;token=754060d1-3cd4-467c-b6a8-649a61711e70" alt=""><figcaption></figcaption></figure>

**For Custom Event and Redemption Code campaigns:**

* Variables map to schema-defined attributes.\
  For example, if your schema includes an integer `steps` attribute:
  * `event.body.steps` becomes available.

This enables expressions like:

```
1 * event.body.steps
```

to award 1 point per step counted in the event payload.

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2Fl9TGEmlJkAWi2Wj47P9V%2Fimage.png?alt=media&#x26;token=c5e79009-2617-420d-a5ae-07b3f2045e8c" alt=""><figcaption></figcaption></figure>

***

### 💳 Wallet Balance Variables

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FJ5UgqTFHrAbZMHiBwua1%2Fimage.png?alt=media&#x26;token=4f83e128-5f06-4d7d-bc1b-62735963f550" alt=""><figcaption></figcaption></figure>

Under the **Variables** tab, you'll also find wallet-related data that can be used in conditions:

* `customer.getWallet('<walletType>').activeUnits`
* `customer.getWallet('<walletType>').blockedUnits`
* `customer.getWallet('<walletType>').pendingUnits`

Use these to set effects like “Give triple points for all active points” or “Deduct all currently active points”

***

### 🎯 Templates

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2F7DXLEAFD27NY3vVD1Hkb%2Fimage.png?alt=media&#x26;token=bad79f5e-7225-4d9b-a592-2aa487ae99a7" alt=""><figcaption></figcaption></figure>

Common formula templates are available under **Templates**, such as:

* Fixed rewards (e.g., `100` for 100 points)
* Multipliers tied to transaction or event data:

  ```
  10*transaction.sku('ABC123').qty
  20*transaction.maker('BrandX').qty
  1*transaction.grossValue
  ```

Selecting a template inserts proper syntax without manual typing, saving time and reducing errors.

***

### 🛠 Building Custom Expressions

Once a template or variable is inserted, you can further refine using supported operations and functions:

* Math operators: `+ - * /`
* Date functions:

  ```
  add_days_to_date(executionContext.processedAt, 15)
  add_days_to_date(transaction.purchasedAt, 5)
  ```
* Member custom attribute conversions:

  ```
  add_days_to_date(
    to_date(agg(customer.labels).getLabelValue('subscription_end_date')),
    6
  )
  ```

These can set dynamic expiration/pending dates or attribute-based caps.

***

### ✅ Benefits

* **Speed & accuracy**: Avoid typing errors and learn variable options as you go
* **Context awareness**: Only relevant templates and data appear based on the selected trigger
* **Advanced logic at your fingertips**: Combine templates and variables for powerful conditional logic

***

### 📌 Tips & Best Practices

* **Explore both categories** in the dropdown—templates and variables each serve a role.
* For **transaction campaigns**, item-level filters enable fine-grained logic (e.g., deduct only for high-value returns).
* For **custom events**, verify the schema matches your attribute names so variables appear correctly.
* Use **wallet variables** to manage campaign eligibility or prevent over-issuing rewards.
* **Test formulas** using the campaign simulator to ensure values are computed as expected.
