I am creating an automation script in transferring data from a source table to a target table. The source contains AI generated responses so everything is in text. I have 4 fields in the target table as single-select fields and I found out that the error I am getting is for those fields. Here's the code below. Hope someone can help.
Getting this "Error updating record: Field "fldkFF6U0cEliKKyy" cannot accept the provided value."
let sourceTable = base.getTable('Update Repository');
let targetTable = base.getTable('UPdates');
let inputConfig = input.config();
let recordId = inputConfig.recordId;
let newRecord = inputConfig.newRecord;
// Fetch the record from the source table
let record = await sourceTable.selectRecordAsync(recordId);
// Fields where AI responses are stored in the source table
let flag1 = record.getCellValue('Name change - AI');
let flag3 = record.getCellValue('Future Fundraising - AI');
let flag4 = record.getCellValue('Future Tokens - AI');
let flag5 = record.getCellValue('Future Exit - AI');
let flag6 = record.getCellValue('Future Shutdown - AI');
let flag7 = record.getCellValue('One-liner AI');
let flag8 = record.getCellValue('Website Update - AI');
let flag9 = record.getCellValue('New Investors - AI');
let daterecord = record.getCellValue('Date');
function isFlagPresent(flag) {
return flag !== 'None' && flag !== 'None.';
}
// Define valid options for single select fields
const validOptions = {
Future_Raise: ['Mentioned', 'Not mentioned'],
Future_Tokens: ['Mentioned', 'Not mentioned'],
Future_Exit: ['Mentioned', 'Not mentioned'],
Future_Shutdown: ['Mentioned', 'Not mentioned'],
};
if (newRecord) {
let updateFields = {
'Brand_Up': isFlagPresent(flag1) ? flag1 : null,
'Future_Raise': isFlagPresent(flag3) && validOptions.Future_Raise.includes('Mentioned') ? 'Mentioned' : 'Not mentioned',
'Future_Tokens': isFlagPresent(flag4) && validOptions.Future_Tokens.includes('Mentioned') ? 'Mentioned' : 'Not mentioned',
'Future_Exit': isFlagPresent(flag5) && validOptions.Future_Exit.includes('Mentioned') ? 'Mentioned' : 'Not mentioned',
'Future_Shutdown': isFlagPresent(flag6) && validOptions.Future_Shutdown.includes('Mentioned') ? 'Mentioned' : 'Not mentioned',
'1Liner_Up': isFlagPresent(flag7) ? flag7 : null,
'Co-URL_Up': isFlagPresent(flag8) && flag8.startsWith("http") ? flag8 : null, // Ensure valid URL
'New Investors_Up': isFlagPresent(flag9) ? flag9 : null,
'Up_Date': daterecord ? daterecord : undefined,
};
// Log the update fields to check their values
console.log("Update Fields:", JSON.stringify(updateFields, null, 2));
// Check if any field is undefined
for (const [key, value] of Object.entries(updateFields)) {
if (value === undefined) {
console.warn(`Field "${key}" is undefined. Skipping...`);
delete updateFields[key]; // Optionally, remove undefined fields
}
}
// Update the existing record in the target table
try {
await targetTable.updateRecordAsync(newRecord, updateFields);
console.log(`Record ${newRecord} updated successfully.`);
} catch (error) {
console.error(`Error updating record: ${error.message}`);
}
} else {
throw new Error('No target record ID provided for updating.');
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.