Feb 11, 2023 06:48 AM
Hi, i am using Aeropage to deal with recent update regarding the attachment url. I have a code as follows:
const table = base.getTable("Inventory")
const recordsQuery = await table.selectRecordsAsync();
let updateArray = [];
// iterate over all records
recordsQuery.records.forEach(record => {
const attField = record.getCellValue("image");
// iterate over object and save as url
if(attField) {
let urlArray = [];
let aeropage = "https://media.aeropage.io/api/imgcache/token/24e60d5167326c730fd9922adb892288/"+record.id+"?attachment=";
attField.forEach(item => urlArray.push(aeropage+item.id))
// attField.forEach(item => urlArray.push(item.url))
const urlString = urlArray.join(', ')
updateArray.push({id: record.id, fields: {"Joined": urlString}})
}
if(attField == null) {
updateArray.push({id: record.id, fields: {"Joined": ""}})
}
})
// update records
while (updateArray.length > 0) {
await table.updateRecordsAsync(updateArray.slice(0, 50));
updateArray = updateArray.slice(50);
}
console.log("Done")
My goal is to get the "Joined" field filled with data like this:
https://media.aeropage.io/api/imgcache/token/24e60d5167326c730fd9922adb892288/recLSywD4sUQP71Tv?attachment=attGr0RxyRO9kLrv5, https://media.aeropage.io/api/imgcache/token/24e60d5167326c730fd9922adb892288/recLSywD4sUQP71Tv?attachment=attMBReszzKhQbBSe, https://media.aeropage.io/api/imgcache/token/24e60d5167326c730fd9922adb892288/recLSywD4sUQP71Tv?attachment=attyaTjq0XACerimj
It seems that my code is not working. Please help me identify what am i missing. Thanks!
Feb 11, 2023 02:42 PM
Hi Kenny,
Maybe your recordsQuery is missing the 'fields' clause?:
const recordsQuery = await table.selectRecordsAsync( {fields: ["image", "Joined"]} );