All Collections
Versions 3.0 and 2.0
Implement
Portal 2.0
How do I use Field Hooks to access multiple columns or fields?
How do I use Field Hooks to access multiple columns or fields?
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

This article is for Flatfile's Portal 2.0. If you'd like to check out the latest version of the Flatfile Data Exchange Platform, click here!

When configuring your Portal 2.0 importer, there may be times when you need to validate a pair of columns or multiple columns. However, Field Hooks can only access one column at a time.

Our suggested solution is to use a nested Field Hook. Nesting the Field Hooks you would like to use gives you access to multiple columns of data at once.

Remember, Field Hooks will always be executed in the order they were registered. Therefore, in order to nest a Field Hook, you first register a Field Hook for one field, store those values in the local variable, and then use the stored values to compare to the second Field Hook.

The following code example is shows the method we suggest using to nest Field Hooks:

let namesrobotImporter.registerFieldHook('name',
(values) => {
    names = values.reduce((acc, [value, index]) => {
        acc[index] = value
        return acc
   },
{})})robotImporter.registerFieldHook('shield-color', (values) => {
    return values.map(([value, index]) => [
       {
            value: names[index],
            info: [{ message: 'changed to name', level: 'warning' }]
       },
        index
   ]
)})

In the example above, we’ve replaced the values in the shield-color field with values from the names field.

Did this answer your question?