// Setup start
const mainTable = base.getTable(“Inventory”)
const mainTable_imageFieldName = “image1”
const mainTable_nameFieldName = “Deskera No”
// Setup end
const mainQuery = await mainTable.selectRecordsAsync({
fields:[mainTable_nameFieldName, mainTable_imageFieldName]
})// Build new attachment data
let updates =
for (let record of mainQuery.records) {
let name = record.getCellValue(mainTable_nameFieldName)
let attachments = record.getCellValue(mainTable_imageFieldName)
if (attachments != null && attachments.length ) {
for (let attachment of attachments){
let parts = attachment.filename.split(“.”)
let ext = parts[parts.length - 1]
let fileNumber = “0” + (attachments.indexOf(attachment) + 1)
let newName = name + “-” + fileNumber+“.”+ext
// let newName =${name}-${fileNumber}.${ext}
// let attachmentName = name + " - " + attachment.filenameupdates.push({ id: record.id, fields: { [mainTable_imageFieldName]: [{ url: attachment.url, // filename: attachmentName filename: newName }] } }) } }}
// Update records
while (updates.length) {
await mainTable.updateRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}
I have this code but then it updates the name but only returns the last image. May i know that is the issue?
