Implement Conditional Logic

Use includeIf expressions to dynamically include or skip steps, envelopes, and documents based on entity data.

Where Conditions Apply

Element Effect
Envelope includeIf Skip the entire envelope and its documents
Document includeIf Skip a single document within an envelope
Step includeIf Skip a step (and all its children if a group)

All conditions are JSONata expressions evaluated against the blueprint's input data. They must return true to include the element. If includeIf is omitted, the element is always included.

Conditional Envelopes

Include an envelope only when relevant:

envelopes:
  - key: offer_envelope
    documents:
      - key: offer_letter
        template: offer_letter@1.0.0

  - key: benefits_envelope
    includeIf: '$.position.includesBenefits'
    documents:
      - key: benefits_form
        template: benefits_enrollment@1.0.0

When includesBenefits is false, the entire benefits envelope is omitted.

Conditional Documents

Include specific documents within an envelope:

envelopes:
  - key: compliance_envelope
    documents:
      - key: nda
        template: nda@1.0.0

      - key: ip_agreement
        template: ip_agreement@1.0.0
        includeIf: '$.position.department = "Engineering"'

The NDA is always included; the IP agreement only appears for Engineering hires.

Conditional Steps

Skip a step when a condition isn't met. Here, the manager approval step only runs for senior positions:

orchestration:
  key: root
  type: group
  execution: sequential
  children:
    - key: hr_sends_offer
      type: participant
      participant: hr_manager
      action:
        type: sign
        envelope: offer_envelope
        assignments:
          - document: offer_letter
            role: hr_representative

    - key: manager_approves
      type: participant
      participant: hiring_manager
      includeIf: '$.position.level > 3'
      action:
        type: sign
        envelope: offer_envelope
        assignments:
          - document: offer_letter
            role: manager

    - key: new_hire_accepts
      type: participant
      participant: new_hire
      action:
        type: sign
        envelope: offer_envelope
        assignments:
          - document: offer_letter
            role: employee

When $.position.level is 3 or below, the manager_approves step is skipped entirely.

Optional Signers

Give an optional signer, such as a second buyer, an includeIf on their own step:

participants:
  - key: buyer_1
    name:
      expression: '$.offer.buyers[0].name'
    email:
      expression: '$.offer.buyers[0].email'
  - key: buyer_2
    name:
      expression: '$.offer.buyers[1].name'
    email:
      expression: '$.offer.buyers[1].email'

orchestration:
  key: buyers_sign
  name: Buyers sign
  type: group
  execution: parallel
  children:
    - key: buyer_1_signs
      name: First buyer signs
      type: participant
      participant: buyer_1
      action:
        type: sign
        envelope: offer_envelope
        assignments:
          - document: purchase_offer
            role: buyer_1

    - key: buyer_2_signs
      name: Second buyer signs
      type: participant
      participant: buyer_2
      includeIf: '$count($.offer.buyers) > 1'
      action:
        type: sign
        envelope: offer_envelope
        assignments:
          - document: purchase_offer
            role: buyer_2
  • includeIf is evaluated once, when the workflow is created. A step it leaves out is not part of the workflow, and the other signers complete the envelope without it.
  • If every step of a group could be left out, give the group the same includeIf.
  • Leave a signer out with includeIf, never with an empty email.
  • In the template's transform, compute a flag from the same condition ("hasSecondBuyer": $count($.offer.buyers) > 1) and wrap the signer's signature block in {{#if hasSecondBuyer}}. Add a scenario for each case.

Expression Examples

A few patterns that show up often. See JSONata Expressions for the full language reference.

# Simple property check
includeIf: '$.deal.value > 100000'

# Combining conditions
includeIf: '$.client.tier = "Enterprise" and $.deal.value > 50000'

# Checking existence
includeIf: '$exists($.employee.manager)'

# Array length
includeIf: '$count($.supplements) > 0'

Tips

  • For complex conditions, factor the logic into a Custom Function and call it from includeIf.
  • Use $exists() before accessing optional properties to avoid evaluation errors.
  • Cover each branch with a Scenario so you can preview both the include-this-step and skip-this-step paths.