Hey guys,
I am trying to find a way to relink Personnel records on a base with synced tabled from 2 different bases in order to limit interface views off Airtable accounts
Base Personnel - All Personnel info including airtable account using the User Field type
Base Project Tracker - Overall project information including Personnel like producers linked to record on a synced table from the Personnel base. Airtable accounts are a lookup field.
Base Asset Tracker - Synced to Project Tracker to assign assets, pulls over information like producers. Also synced to Personnel base to assign assets to people.
The synced Project table on the asset tracker currently pulls over the producer information but obviously as a single test field with the producers in a string out. Obviously I can't change the field type to relink to the Personnel synced table on the asset tracker.
I've tired an automation that finds records with the matching name but that does not seem to to work since there can be multiple producers attached to a single project.
I've also tired a scripting automation to pull the string apart and relink, but I can't seem to get it to work.
let projectsTable = base.getTable('Projects');
let personnelTable = base.getTable('Personnel');
// Fetch all records from the "Projects" table.
let projectsRecords = await projectsTable.selectRecordsAsync();
// Create a mapping of producer names to their corresponding project records.
let producerToProjectMapping = {};
// Iterate through each project record.
for (let projectRecord of projectsRecords.records) {
// Get the string of names from the "Additional Producers" field.
let additionalProducersString = projectRecord.getCellValueAsString('Additional Producers');
if (additionalProducersString) {
// Split the string into an array of producer names.
let producerNames = additionalProducersString.split(', ');
// Iterate through each producer name.
for (let producerName of producerNames) {
// Store the project record for this producer name.
if (!producerToProjectMapping[producerName]) {
producerToProjectMapping[producerName] = [];
}
producerToProjectMapping[producerName].push(projectRecord);
}
}
}
// Iterate through the mapping and update personnel records.
for (let producerName in producerToProjectMapping) {
// Fetch the corresponding personnel record for this producer name.
let matchingPersonnelRecords = await personnelTable.selectRecordsAsync({
filterByFormula: `AND({Full Name} = "${producerName}", {Additional Producers Project} = BLANK())`
});
// Check if there is exactly one matching personnel record.
if (matchingPersonnelRecords.records.length === 1) {
let personnelRecord = matchingPersonnelRecords.records[0];
// Extract the projects associated with this producer name.
let projectsToLink = producerToProjectMapping[producerName];
// Extract the project IDs.
let projectIdsToLink = projectsToLink.map(project => ({ id: project.id }));
// Update the "Additional Producers Project" field to link to the projects.
await personnelTable.updateRecordAsync(personnelRecord, {
'Additional Producers Project': projectIdsToLink
});
}
}
Does anyone know of a way to relink or if there's a better way to structure this?