Docs

A decision table with a limit

How to set up a decision table with a per-customer campaign limit — definition, row, evaluation for a customer, an interaction type that references the row, and the rejection once the limit is used up.

By the end you will have a decision table that says whether a customer is entitled to something in a campaign and won't let them get it twice. The Nordtone example: in the “City tour” campaign a promoter hands a customer a starter kit — one per customer. The CRM won't hand the same customer a second kit: an interaction referencing a used-up row is rejected. Table definitions and types are set up by roles with the “Settings → All settings, users and roles” permission (only the system “Administrator” role), rows by roles with the “Decision table rows → Edit and import” permission.

What you need

  • The “Settings → All settings, users and roles” permission.
  • A campaigns catalog with the campaign you need — at Nordtone it is “Campaigns” with the “City tour” campaign of the “Field activations” project. The per-campaign limit is counted only by the campaigns catalog (Request parameters).
  • For the over-limit rejection — an app that creates interactions through the API: an API client with the decisions:evaluate and interactions:write permissions and the “Field activations” project. Both requests pass the customer id: if the app does not store it and looks the customer up by phone, add the customers:read permission.

Describe the table

  1. Open Settings → Table definitions and press New table.
  2. Enter starter_kit in Code, and in Name enter “Starter kit” for English and «Стартовый набор» for Russian.
  3. In the Request parameters block, press Add parameter and fill it in: Name — campaign, Type — Catalog item, Catalog — “Campaigns”, Label — “Campaign”.
  4. In Campaign parameter, pick campaign.
  5. In the Columns block, press Key column and fill it in: Code — campaign, the list Parameter — campaign, the operator — equals, Label — “Campaign”.
  6. In the Result schema block, enter kit as the Field code of the ready-made field, set the type to String and tick Required.
  7. In the Projects block, tick “Field activations”.
  8. Press Create table.
New Starter kit table: the campaign parameter from the Campaigns catalog, the campaign parameter setting and the key column

The table is created disabled and its definition opens. Press Enable in the header and confirm with Enable in the dialog. The form blocks are described under Table definitions.

Add a row with a limit

  1. Open Data → Decision tables, the “Starter kit” table, and press New row.
  2. Enter city_tour_kit in Code and leave Priority at 0.
  3. In the “Campaign” cell, untick Any value and find the “City tour” campaign.
  4. In the Result block, enter “Headphone care kit” in the kit field.
  5. In the Per-customer limits block, enter 1 in Per campaign. Leave the other limits and the Validity period block empty.
  6. Press Create row.

A per-campaign limit means: once per customer in each campaign the request names. There are also Per day and All time limits — see Per-customer limits.

Evaluate it for a customer

  1. On the table screen, press Evaluate.
  2. In the Customer field, find Anna Lange.
  3. Pick “City tour” in the “Campaign” parameter and press Evaluate in the panel.

“Matched: 1” lists the city_tour_kit row with its result and a “0 of 1 used” counter. An evaluation records nothing and doesn't use the limit — only an interaction referencing the row does.

Link the row to an interaction

For handing out a kit to use up the limit, you need an interaction type that references the table's rows.

  1. Open Settings → Entity types, the Interaction types tab, and press New type.
  2. Enter kit_handover in Code, and in Label enter “Starter kit handover” for English and «Выдача стартового набора» for Russian.
  3. In the Projects block, tick “Field activations” — the type's projects must be within the table's projects.
  4. In the Decision table line block, pick “Starter kit” in Decision table.
  5. In the Parameter sources block, pick Campaign for the “Campaign” parameter — the interaction's own campaign.
  6. Tick Decision line required: an interaction of this type won't be created without a line reference.
  7. Press Create type.

The other type settings are described under Entity types.

Rejection over the limit

The promoter app records the handover through the API:

  1. it evaluates the table for the customer — POST /decision-tables/starter_kit/evaluate with the field project and campaign = city_tour — and takes the id of the matched row;
  2. it creates a kit_handover interaction in the field project with the city_tour campaign and that id in decision_line_id.

The first such interaction goes through and uses up the row's limit. The API rejects a second one for the same customer in the same campaign with status 422 and the LIMIT_REACHED reason: the interaction isn't recorded. Send each create request with its own Idempotency-Key header: a request with a reused key would get the first response back.

Check the result

  • Evaluate Anna Lange in the “City tour” campaign again: the city_tour_kit row is now under “Rejected” with the “Limit reached” reason and a “1 of 1 used” counter (Evaluate for a customer).
  • In Data → API log, find the rejected request by the interactions path and the “4xx — client error” filter: the response carries LIMIT_REACHED and the used-up limit (Search and filters).
  • The customer card's Interactions tab has one “Starter kit handover”.

What's next