Skip to content

Evaluate return eligibility by product line

Use this workflow to evaluate an unopened product return against the window for its product line. Standard products have a 30-day window and Outlet products have a 14-day window. Both policies use the same evaluateReturn function inputs and return the same decision and reason fields.

Before you begin

Publish the Return Eligibility template and both policies in the tenant where the workflow will run. See Policy Templates and Policies for setup.

The repository contains the exported template, the 30-day policy, and the 14-day policy. Use the 30-day source rules and 14-day source rules if you regenerate the functions in another tenant.

Workflow flow

flowchart TD
    Start([Webhook receives the return facts]) --> Supported{"If Condition · Supported product line?"}
    Supported -->|Yes| Route{"Switch · Product line"}
    Supported -->|No| Review(["Return · Manual review"])
    Route -->|STANDARD| Standard["Policy · Evaluate the 30-day window"]
    Route -->|OUTLET| Outlet["Policy · Evaluate the 14-day window"]
    Standard --> StandardResult(["Return · 30-day policy decision"])
    Outlet --> OutletResult(["Return · 14-day policy decision"])

Configure the workflow

  1. In Settings → Triggers → Webhook, define these inputs.

    Input Type Example value
    productLine String STANDARD or OUTLET
    daysSinceDelivery Integer 20
    condition String unopened or opened
  2. Add an If Condition before the Switch. Use {{$context.$triggers.REST.$input.productLine == 'STANDARD' || $context.$triggers.REST.$input.productLine == 'OUTLET'}}. Connect the false path to a Return node with the value {"decision":"MANUAL_REVIEW","reason":"No return policy is configured for this product line."}.

  3. On the true path, set the Switch node's Case Expression to {{$context.$triggers.REST.$input.productLine}}. Add the two cases and connect each to its own Policy node.

    Switch case Policy node code Published policy Function
    STANDARD CHECK_STANDARD_RETURN Return Eligibility - 30 Days evaluateReturn
    OUTLET CHECK_OUTLET_RETURN Return Eligibility - 14 Days evaluateReturn
  4. In both Policy nodes, map daysSinceDelivery to {{$context.$triggers.REST.$input.daysSinceDelivery}} and condition to {{$context.$triggers.REST.$input.condition}}.

  5. Add a Return node after each Policy node. Set Return Value to {{$context.$nodes.CHECK_STANDARD_RETURN.$output}} on the Standard path and {{$context.$nodes.CHECK_OUTLET_RETURN.$output}} on the Outlet path. To read only the decision in a downstream condition, use {{$context.$nodes.CHECK_STANDARD_RETURN.$output.decision}} or the corresponding Outlet node expression.

Run the workflow

Publish the workflow and invoke its webhook. Use the same age and condition in both requests so only the product line changes.

Standard product

Sample request

{
  "invocationMode": "END_USER",
  "message": "Check return eligibility.",
  "parameters": {
    "productLine": "STANDARD",
    "daysSinceDelivery": 20,
    "condition": "unopened"
  }
}

Sample workflow output

{
  "decision": "ELIGIBLE",
  "reason": "The product is unopened and was delivered within 30 days."
}

Outlet product

Sample request

{
  "invocationMode": "END_USER",
  "message": "Check return eligibility.",
  "parameters": {
    "productLine": "OUTLET",
    "daysSinceDelivery": 20,
    "condition": "unopened"
  }
}

Sample workflow output

{
  "decision": "INELIGIBLE",
  "reason": "The product is unopened but was delivered more than 14 days ago."
}

Expected behavior

Scenario Expected decision
Unopened Standard return at day 30 ELIGIBLE
Unopened Standard return at day 31 INELIGIBLE
Unopened Outlet return at day 14 ELIGIBLE
Unopened Outlet return at day 15 INELIGIBLE
Opened item on either supported product line INELIGIBLE
Unsupported product line MANUAL_REVIEW. The workflow skips both policies.

See If Condition, Switch, Policy, and Return.