Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Hard Code Airtable Provided Script

Topic Labels: Scripting extentions
515 2
Showing results for 
Search instead for 
Did you mean: 

I am wanting to hard code the table variables into the script airtable provides to convert URL’s into attachments, so that I can run it via an automation.

This is the script:

 let settings = input.config({

        title: "Convert URLs to attachments",

        description: `This script will download all attachments from a URL into an attachment field. The 

    source field can be a URL field or any text field containing a URL. Each cell should only contain a single URL.`,

        items: [

            input.config.table("table", { label: "Table" }),

            input.config.field("urlField", {

                parentTable: "table",

                label: "URL field",


            input.config.field("attachmentField", {

                parentTable: "table",

                label: "Attachment field",

                description: "URLs will be downloaded into this field",




    async function convertURLsToAttachments() {

        let { table, urlField, attachmentField } = settings;

        if (attachmentField.type !== "multipleAttachments") {


                `${} is not a attachment field.\nRun the script again when you have an attachment field.`




        let skipAlreadySet = await input.buttonsAsync(

            "Skip attachment entries that already have files?",


                { label: "Yes", value: true },

                { label: "No", value: false },



        let updates = [];

        for (let record of (

            await table.selectRecordsAsync({ fields: [urlField, attachmentField] })

        ).records) {

            let existingAttachments = record.getCellValue(attachmentField) || [];

            if (skipAlreadySet && existingAttachments.length) continue;

            let urls = record.getCellValueAsString(urlField);

            if (typeof urls !== "string") continue;

            let attachmentsFromUrls = urls.split("\n").map((url) => ({ url }));



                fields: {

                    []: [







        for (let i = 0; i < updates.length; i += 50) {

            await table.updateRecordsAsync(updates.slice(i, i + 50));



    await convertURLsToAttachments();
2 Replies 2

I don’t quite know if this is what you mean…

const table = base.tables.filter( t => === "<YOUR TABLE NAME>");

But this will allow you to ‘hard code’ from the available tables, so that your Automation will recognize where the attachments are. You can’t just remove the input.config.table portion though but this should get you started.

You can do something like this to replace the input.config section …

let settings = {}
settings.table = base.getTable("Table Name")
settings.urlField = settings.table.getField("url field name")
settings.attachmentField = settings.table.getField("attachment field name")