Custom Logic Block & Tables

1. Purpose

The Custom Logic Block lets you run custom JavaScript or Python over input documents and/or sources and return either:

  • the same document with updated fields (Pass original: ON), or

  • a new VC (unsigned or signed) (Pass original: OFF).

Access to table data inside expressions is identical to AutoCalculate and uses the table helper:

  • table.keys(tbl) β†’ column names

  • table.col(tbl, keyOrIndex) β†’ column values

  • table.rows(tbl) β†’ data rows

  • table.cell(tbl, rowIndex, keyOrIndex) β†’ a cell

  • table.num(value) β†’ safe number conversion

Note: the expression has access to documents, sources, table, and done(result) to return the result.

2. When to use each mode

Pass original: ON

  • You return the entire document (or an array) after modifications.

  • Does not create a new VC, does not validate by schema, and does not sign.

  • Easiest and most reliable way to β€œcompute and write a field” in an existing VC.

Pass original: OFF

  • Creates a new VC (unsigned or signed).

  • Requires additional setup:

  • Unsigned VC β†’ return only the subject (or an array of subjects). Must include valid id, type, @context (or set outputSchema, which provides @context/type).

  • Signed VC β†’ set outputSchema, configure documentSigner, and return JSON matching the schema.

If any of these are missing, VC build/validation may fail (e.g., β€œCannot read properties of undefined (reading 'codeVersion')”, β€œβ€¦getId…”).

3. Working expressions (Pass original: ON)

3.1. Subtotal by table and grand total with a form field

  • Sums Qty * Price per row.

  • Adds a numeric form field field21.

  • Writes results to calcSubtotal and calcTotal in the subject.

3.2. Sum a column by name and write to field21

  • Finds the β€œPrice” column by name.

  • Sums values and writes the result to field21 (works with nested/flat schema).

3.3. Index-only

  • Sums the third column (index 2) by index only.

  • Writes the result to field21.

4. Doing the same with Pass original: OFF

Unsigned VC: ON

Return only credentialSubject (or an array). Make sure you provide valid:

  • id (can be set or generated),

  • type, @context (may come from outputSchema if set in the block).

Without these, raw VC build will fail.

Signed VC (Unsigned: OFF)

  • Set outputSchema.

  • Return a subject that matches the schema.

  • Configure documentSigner.

The block will then:

  • validate the subject against the schema,

  • add service fields,

  • sign the VC.

Any mismatch with outputSchema will cause validation/signing errors.

Last updated