Validate an invoice attachment¶
Use this workflow to check an invoice PDF attached to a Fusion invoice record. Apply a published policy to each extracted line and return which lines need review.
Before you begin¶
Publish an invoice schema with a lineItems array containing lineNumber, quantity, and amount. Publish a policy function that accepts quantity and amount and returns a Boolean needsReview. For this example, flag a nonpositive quantity or a negative amount.
Workflow flow¶
flowchart TD
Start([Webhook receives invoiceId]) --> Init["Set Variables · Initialize flagged lines"]
Init --> Extract["Document Processor · Extract invoice lines"]
Extract -->|Invalid or unreadable| Error([Handle the extraction error])
Extract -->|Valid| Loop{"For Loop · Next invoice line?"}
Loop -->|Yes| Check["Policy · Evaluate quantity and amount"]
Check --> Append["Code · Append the line if it needs review"]
Append --> Save["Set Variables · Save the flagged lines"]
Save --> Loop
Loop -->|No| Review{"If Condition · Any flagged lines?"}
Review -->|Yes| Link["Tool · Get the invoice deep link"]
Link --> Result([Return the invoice ID, flagged lines, and link if available])
Review -->|No| Result
Configure the workflow¶
- Webhook and initial state. Define a String input named
invoiceId. Declare an Array variable namedflaggedLinesand initialize it to[]with Set Variables before processing. - Document Processor. Add node
EXTRACT_INVOICEand select the Business Object function for invoice attachments. Map the invoice ID from{{$context.$triggers.REST.$input.invoiceId}}. Enable Use LLM for data extraction and select the published Schema Template. The loop expectslineItemsat the output root. Adapt the collection expression if your schema returns a different shape. Route unreadable documents or invalid extraction results to an error path. - For Loop. Add node
CHECK_LINES. Set Collection to{{$context.$nodes.EXTRACT_INVOICE.$output.lineItems}}and Processing Mode to Sequential because iterations update a shared array. - Policy. Within the loop, add node
CHECK_LINE_POLICY. Map the function's quantity and amount to{{$context.$nodes.CHECK_LINES.$currentItem.quantity}}and{{$context.$nodes.CHECK_LINES.$currentItem.amount}}. Validate that the mapped values are numeric before evaluating the policy. - Code and Set Variables. Add a Code node inside the loop to return a new Array. When
{{$context.$nodes.CHECK_LINE_POLICY.$output.needsReview}}is true, append the current item'slineNumberto the existingflaggedLinesarray. Assign the Code node's$output.resultback toflaggedLineswith Set Variables. - If Condition and Tool. If
{{$context.$variables.flaggedLines.length > 0}}, use a Tool node with Type set to Deep Link. Select the invoice navigation tool and map its internal invoice ID from the webhook. Inspect the tool output to identify the URL property before returning it. - Return. On each path, return the invoice ID and
flaggedLines. Include the navigation URL on the review path if the selected tool returned one.
Run the invoice validation workflow¶
Attach a test PDF to a Fusion invoice. Give line 1 a quantity of 2 and amount of 120, and line 2 a quantity of 0 and amount of 40. Invoke the webhook with the internal invoice identifier. Replace the sample identifier with one from your tenant.
Sample request
{
"invocationMode": "END_USER",
"message": "Validate the attached invoice.",
"parameters": {
"invoiceId": "300100000000001"
}
}
Sample workflow output
{
"invoiceId": "300100000000001",
"flaggedLines": [2],
"reviewUrl": "https://fusion.example.com/fscmUI/faces/deeplink?objType=AP_VIEWINVOICE&action=VIEW&objKey=InvoiceId=300100000000001"
}
Expected behavior¶
| Scenario | Expected behavior |
|---|---|
| One line violates the policy | Only its line number appears in flaggedLines, and the review link points to the invoice. |
| All lines pass | The workflow returns an empty array and skips the Deep Link step. |
| PDF is unreadable or extraction misses a required amount | The workflow takes the error path and does not show a successful validation. |
Related guides
Document Processor · For Loop · Policy · Set Variables · Tool