Action

Airtable: Import Records

Posted by agiletortoise, Last update over 1 year ago

Demo of scripting record import from Airtable. Needs to be modified to have baseId and tableName values that map to an actual table in your account.

See Airtable integration guide for usage details.

Steps

  • script

    // set values from your account
    let baseId = "appOSVpC6cay6jFbX"
    let tableName = "Debug"
    
    // create Airtable value
    let at = new Airtable()
    let content = `# Imported Records, Table: ${tableName}
    
    `
    
    // request list of records in the table
    let results = at.listRecords(baseId, tableName)
    if (results) { // we got values!
    	let records = results["records"] // array of records
    	// loop over records array
    	for (const record of records) {
    		// get fields from record
    		// loop over them and make a line
    		let fields = record["fields"]
    		let vals = []
    		let keys = Object.keys(fields).sort()
    		for (const fieldName of keys) {
    			vals.push(fields[fieldName])
    		}
    		content += vals.join(", ")
    		content += "\n"
    	}
    	// create a new draft with the results
    	let d = new Draft()
    	d.content = content
    	d.update()
    	editor.load(d)
    	app.setClipboard(JSON.stringify(records))
    }
    else { // something when wrong, log error
    	console.log(at.lastError)
    	context.fail()
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.