A9 validate and transform

Run custom function code to valid and transform entity.

A9 validate and transform

AI-generated

Overview

This node allows users to run custom JavaScript code to validate and transform an entity within the input data. It is useful in scenarios where data needs to be programmatically checked and modified before further processing, such as data cleansing, enrichment, or validation workflows. For example, a user can add custom properties, validate fields, or generate error messages dynamically based on the entity's content.

Use Case Examples

  1. Adding a custom property to the entity to mark it as processed.
  2. Validating required fields and returning an error message if validation fails.
  3. Transforming entity data structure to match downstream system requirements.

Properties

Name Meaning
Function The JavaScript code to validate and transform the entity. This code receives the current entity and the list of all input items and must return an object containing the transformed entity, a validity flag, and an optional error message.

Output

JSON

  • entity - The transformed and validated entity object returned from the custom function.
  • valid - Boolean flag indicating whether the entity passed validation.
  • errorMessage - Optional string containing an error message if validation failed.

Dependencies

  • Uses the 'vm2' library to safely execute user-provided JavaScript code in a sandboxed environment.

Troubleshooting

  • If the custom function does not return any data, the node throws an error 'No data got returned. Always return an Array of items!'. Ensure the function returns the expected object.
  • If the returned object does not contain the 'entity' property, an error is thrown. The function must always return an object with 'entity'.
  • If the returned object does not contain the 'valid' property, an error is thrown. The function must always return an object with 'valid'.
  • Errors thrown during the execution of the custom function will reject the node execution. Check the function code for syntax or runtime errors.

Discussion