Reformatting Responses
Version 1.5 and greater of the Retrieve Payable node support manipulation of the response using the settings field Format Expression. If you reformat the response, you must ensure the response is structured correctly. Examples of why you may wish to reformat include:
You may wish to concatenate data from multiple fields
You may wish to reformat or change a specific responses value
You may wish to change a value’s attributed field name
Standard Response Format
The response from the TransformAI service is JSON, and must match the following structure:
{
"Pages":1,
"SummaryFields":[
{
"Key":"Value",
"Value":"Value",
"Confidence":99,
"Page":1,
"Sanitized":"Value",
"Type":"Character"
}
]
}
Pages: Integer representing the number of document pages included in the response.
SummaryFields: An array of field objects.
Key: The field to be mapped’s name.
Value: The raw extracted value.
Confidence: The AI’s confidence value for the field’s extracted result.
Page: The page on which the field was found.
Sanitized: A modified version of the extracted value, used when options are enabled in the Node’s settings.
Type: The data type for the extracted value. Values are Date, Amount, or Character.
Sanitization Rules
Sanitized values are based on the following:
Date: Remove tabs, carriage returns, line feeds, and spaces when two or more are found consecutively.
Money: Remove spaces and any occurrence of the string “USD”.
Character: Remove tabs, carriage returns, line feeds, and spaces when two or more are found consecutively.
Authoring Expressions
You MAY NOT alter the format of the standard response structure. For details on authoring expressions, refer to the Expression Exercise.
Expressions are very powerful, and can be very complex. it is recommended they are thoroughly tested with a variety of data sets. Below is an example that reformats two field names.
(
$moddedSummary:=SummaryFields.{"Key":$replace(Key,/^ADDRESS$/,"COMPANYADDRESS"), "Value":Value, "Confidence":Confidence, "Page":Page, "Sanitized":Sanitized,"Type":Type};
$moddedSummary:=$moddedSummary.{"Key":$replace(Key,/^STREET$/,"COMPANYSTREET"), "Value":Value, "Confidence":Confidence, "Page":Page, "Sanitized":Sanitized,"Type":Type};
{
"Pages":$.Pages,
"SummaryFields":$moddedSummary
}
)
Complex functions are wrapped in parens
Variable assignment is handled with := and in the example above, line 2 initializes that variable and changes the ADDRESS field to COMPANYADDRESS while keeping the rest of the object structure intact
Variables can be reused in expressions as demonstrated in line 3
If you did not reuse the variable, you would lose the changes mage in line 2
JSON is then output in the standard format