Select Page
How to View Attachment Fields and IDs from On2Air Backups in Your Storage Drive (includes Script)

How to View Attachment Fields and IDs from On2Air Backups in Your Storage Drive (includes Script)

On2Air Help CenterOn2Air Help Center > On2Air BackupsOn2Air Backups Start a free trial

In this video, you’ll learn how to view Airtable attachment fields, field names, and field IDs from On2Air Backups in your Google Drive, Dropbox, or Box storage drive. This will help you easily identify which Attachments are related to which Airtable fields. You’ll copy a scripting code we provide and add it to the Scripting extension in your Airtable base.

In this tutorial

What is On2Air Backups?

On2Air Backups creates automated backups of your Airtable data and sends the data to your storage drive in Google Drive, Dropbox, and Box.

🎥 Tutorial Video

Airtable Script to View Attachment Fields and IDs

Follow the link below and Copy the script. You’ll then paste it into the Scripting extension in your Airtable base.

Script: https://gist.github.com/on2air/aa8c1a561c110ddc9c132e419bb300b7

/**
 * On2Air Backup Scripts
 * Owned by On2Air.com
 * All rights reserved.
 * Copywrite 2023
 * 
 */

output.markdown("# On2Air Backups Scripts")
output.markdown('##### Scripts assocated with On2Air: Backups. All rights reserved.')
const table = await input.tableAsync("Select Table containing attachments")
const attFields = table.fields.filter( f => f.type === 'multipleAttachments')
output.markdown("# Select an Action")
const options = ['Display Field IDs', 'Search by Record', 'Search by Att']
const selection = await input.buttonsAsync('Select', options)
const index = options.indexOf(selection)
switch(index){
    case 1:{//by record
        output.markdown("## Search by Record Name")
        const recMatch = (await input.textAsync("Enter Search")).toLowerCase()
        const records = (await table.selectRecordsAsync({fields:attFields})).records
        output.table( records.filter( r => r.name.toLowerCase().includes(recMatch)).map( r => {
            const out = {id:r.id,name:r.name}
            for(let af of attFields){
                out[af.name] = (r.getCellValue(af) || []).map( a => a.id + "\t|\t" + a.filename).join("\n")
            }
            return out
        }) )
        break;
    }
    case 0:{//att field
        output.markdown('## Attachment Fields in Table: ' + table.name)
        output.table( attFields.map( af => ({name:af.name, id: af.id})))
        break;
    }
    case 2:{//search by att id
        output.markdown("## Attachment Search")
        const recMatch = (await input.textAsync("Enter Search by Att Value")).toLowerCase()
        const records = (await table.selectRecordsAsync({fields:attFields})).records
        const matches = []
        records.forEach( r => {
            for(let af of attFields){
                const items = (r.getCellValue(af) || [])
                for(let item of items){
                    if(item.id.toLowerCase().includes(recMatch) || item.filename.toLowerCase().includes(recMatch)){
                        matches.push({record_id: r.id, name: r.name, field_id: af.id, field: af.name, att_id: item.id, att_name: item.filename})
                    }
                }
            }
        })
        output.markdown("## Matching Attachments")
        output.table( matches )
        break;
    }
}