Store Original Record Value
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

This article is for the latest version of the Flatfile Data Exchange Platform.

Flatfile's Data Exchange Platform offers record-level metadata to allow you to store extra information about a record that may go beyond what the data owner has provided.

One valuable use for this metadata is the ability to retain the originally supplied value, so you can compare the value that was in the original file with the value after it has undergone any transformations you may have applied or the Data Owner has completed.

Here is an example of how you could store the original value:
โ€‹

import * as Flatfile from "@flatfile/api"; 
// Import the Flatfile API package

// Function to retrieve records, copy values to metadata, and update records
async function copyValuesToMetadataAndUpdate(sheetId: string, api: Flatfile.Api): Promise<void> {
try {
// Step 1: Get all records from the given sheetId
const { data: { records } } = await api.records.get(sheetId);

// Step 2: Copy values to metadata sub-object
const updatedRecords = records.map((record: Flatfile.RecordWithLinks) => {
const updatedValues = { ...record.values };
record.metadata = { ...updatedValues };
return record;
});

// Step 3: Update the records using api.records.update
await api.records.update(sheetId, updatedRecords);
console.log("Records updated successfully!");
} catch (error) {
console.error("Error updating records:", error);
}
}

These metadata values can now be retrieved and used if you need them!

Did this answer your question?