Skip to content

Use case

Invoice and Expense Processing ​

Put the monthly export in, get a validated file out, with every line item checked on the way.

  • Stack Cognipeer Flows
  • Pattern Flow · Back office
  • Read ~4 min

Overview ​

Every month the same file lands: a billing export or a folder of expense claims, and an analyst reconciles it by hand. This flow parses the export, validates each line, builds a CSV and stores it as a file.

Enterprise module

Flows is the enterprise flows module. Run code and the sandbox steps need the Sandbox runtime. See Flows.

The shape of the flow ​

Start (exportText)
   |
   v
Parse JSON / Run code (validate and normalise lines)
   |
   v
For each line --body--> Condition (amount valid?) --false--> Set variables (rejected list)
   |
   done
   v
Run code (build CSV) --> Save file --> End

Build it ​

  1. Take the input the way finance sends it. Declare exportText on the Start node, or read a stored export with Read file (Return as Text (UTF-8)).
  2. Parse and validate before you loop. For JSON exports use Parse JSON with If the text is not valid JSON set to Fail the step, so a bad export stops the run at the first step instead of producing a half-empty file. For CSV or messy text use Run code: it takes the data through Input and returns the lines and a total as its result.
  3. Loop. For each over the validated lines. Inside the body a Condition checks the fields you care about (amount is a number, supplier is not empty). Keep the lines that fail in a run-scoped variable with Set variables so the output can list them.
  4. Build the CSV. A Run code step turns the collected lines into CSV text. A tiny script is easier to review than a chain of data steps.
  5. Save it. Save file into a Document Store bucket with the File name invoices-<month>.csv and If the name exists set to Keep both (unique name).
  6. Declare outputs: the line count, the total, the number of rejected lines and the file id.

Run it ​

Start the flow from the Flows API when the export arrives, or from the Test panel while you build. The run detail shows every step with its input and output, so a number that looks wrong can be traced to the line that produced it.

Pitfalls ​

  • Fail early. An export that does not parse should end the run with an error, not an empty CSV.
  • Do not edit the original. Write a new file and keep the export as it came.
  • Counting events. Cognipeer has no event-tracking step: if you need a spend breakdown, have the flow output the per-supplier totals, or store them in the file you produce.