# 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="/files/7nfzJpNHZrqEpGEfm0UJ" 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="/files/3qSdlHXzYPF1Emt4GgqU" alt=""><figcaption></figcaption></figure>

***

### 💳 Wallet Balance Variables

<figure><img src="/files/fXm4zrMVHR5FSBNaZsxU" 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="/files/E3m3B9eRhut09k6rd5iD" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.openloyalty.io/main-features/campaigns/effects-autocomplete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
