Learn how to process data with Data Hooks
FlatfileRecord
class.
Record-level hooks have access to all fields in a row and should be utilized for operations that require access to multiple fields or when creating a new field.
FlatfileRecord
class provides methods to manipulate and interact with a record in the Flatfile format, including setting values, retrieving values, adding information messages, performing computations, validating fields, and converting the record to JSON format.
Listen for updates to data records, and respond with three types of record hooks: compute
, computeIfPresent
, and validate
. These hooks are available as methods on the FlatfileRecord
class.
FlatfileRecord.compute
compute
will run even when no value is set for the field (see computeIfPresent
).
FlatfileRecord.computeIfPresent
compute
, but only computes a new value if an initial value is provided (not null). Useful for computations that may throw an error on null values.
FlatfileRecord.validate
FlatfileRecord.addInfo()
FlatfileRecord.addError()
FlatfileRecord.addWarning()
recordHook
or a bulkRecordHook
allows for retrieving additional data or performing external operations to enrich or modify existing data. This approach integrates external data sources or services into the data manipulation workflow, enabling real-time or dynamic information to enhance the data. It is particularly useful when fetching related data, validating information, performing calculations, or any operation that relies on external input before modifying the data.
GET
GET
method does just that, then updates the record object with the retrieved data, and handles any errors that may occur during the process.
status
field to “Failed” and add an error message. The modified record is then returned from the recordHook
.
POST
POST
request, then update the record object based on the success or failure of the request. Last, add messages to the fields accordingly.
POST
request to a webhook endpoint using axios. We pass the payload, method, and record as the request body and handle the response.
If the request is successful, we update the status
field of the record to “Success” and add a comment. If an error occurs, we update the status
field to “Failed” and add an error message. The modified record is then returned from the recordHook
.
getLinks
method is a feature of the FlatfileRecord class. When a field in your record is of the Reference Field type and links to another record, getLinks can fetch those linked fields for you.
getLinks
method. Provide the field key of the Reference Field type, the part of the record that holds the reference to the other records, like this:
getLinks
provides access to all related information. It’s particularly useful when you want to perform operations similar to VLOOKUPs in spreadsheets, or when you need to compare data across referenced fields.
For instance, you could use getLinks
to fetch all the fields related to a particular record and enrich your data, or compare the related records for validation.
With getLinks
, processing related datasets becomes much more manageable in Flatfile. This method provides you with an effective way to navigate, enrich, and validate your data.
@flatfile/api
package, then use the api.records.delete()
helper method. This method takes in an array of record IDs and deletes them from the sheet.
Example: