Create conditional expressions

You can create more than one active version of an invoice template per locale, and use conditional expressions to determine which fields appear on a version of an invoice template.

Note: You can only use conditional expressions in templates that you create or that you copy from a marketplace-provided default template. You cannot add conditional expressions to marketplace default templates.

This topic describes how to add a conditional expression to a JSON template. For information about creating and editing JSON templates, see the topics in the Invoice template JSON introduction section.

Following are examples of how can use conditional expressions to manage JSON invoice template content using multiple versions of an invoice template:

Condition type

Conditions

Invoice status

If an invoice is unpaid, the Amount due field appears on the unpaid invoice.

If an invoice is paid, the Amount due field does not appear.

Country

Tax information changes depending on the user’s country.

To add a conditional expression to a JSON template

  1. Go to . The Invoice Templates listing page opens.
  2. Click the gear icon next to the template you want to edit, then select Edit JSON from the drop-down list.
  3. Add one or more conditional expressions, as required.

Sample conditional expressions

Conditional expressions can consist of a single condition or multiple conditions. Following are generic examples of conditional expressions for single and multiple conditions:

Single condition

{
"components": [
{
"data": "",
"description": "",
"style": {
"width": "100%",
"font-size": "6pt"
},
"isConditional": true,
"type": "markdownText",
"conditionalExpr": {
"condition": {
"operator": "ValueOf",
"key": "{{Invoice Status}}"
},
"effects": {
"UNPAID": {
"update": {
"data": "**WIRE PAYMENT INSTRUCTIONS** \nABC Bank \nNew York \nCredit: XYZ Digital Inc. \n**REFERENCE: {{Invoice Number}}**"
},
"type": "update"
}
}
}
}
],
"description": "",
"type": "cell",
"properties": {
"visible": true,
"position": "right",
"selected": false
}
}

Multiple conditions

{
"components": [
{
"data": "INVOICE  \n**{{Invoice Number}}**\n\nAMOUNT DUE  \n**{{Balance Due}}**\n\nINVOICE DATE  \n**{{Date}}**\n\nDUE DATE  \n**{{Invoice Due Date}}**",
"description": "Invoice Summary",
"style": {
"background-color": "#EAEAEA"
},
"type": "markdownText",
"isConditional": true,
"conditionalExpr": {
"condition": {
"operator": "AND",
"values": [
{
"operator": "Bool",
"key": "{{isCreditNote}}",
"value": "true"
},
{
"operator": "StringEquals",
"key": "{{invoiceStatus}}",
"value": "PAID"
}
]
},
"effects": {
"true": {
"update": {
"data": "CREDIT NOTE  \n**{{Invoice Number}}**\n\nAMOUNT DUE  \n**{{Balance Due}}**\n\nCREDIT NOTE DATE  \n**{{Date}}**\n\nDUE DATE  \n**{{Invoice Due Date}}**"
},
"type": "update"
},
"false": {
"update": {
"data": "INVOICE  \n**{{Invoice Number}}**\n\nAMOUNT DUE  \n**{{Balance Due}}**\n\nINVOICE DATE  \n**{{Date}}**\n\nDUE DATE  \n**{{Invoice Due Date}}**"
},
"type": "update"
}
}
}
}
],
"type": "cell",
"properties": {
"visible": true,
"selected": false
}
}