Help

Updating Attachment field with full path

Solved
Jump to Solution
3096 6
cancel
Showing results for 
Search instead for 
Did you mean: 
mrcard
4 - Data Explorer
4 - Data Explorer

Hi there,

I'm new to the Airtable Community and was hoping someone here might shed some light on a script I'm trying to implement. I am receiving data from a third party form via an AT Webhook. I need to concatenate the image path (ImgPath) submitted from the form when it includes an attachment to create a full URL and then update the PhotoURL field which is set as an attachment in the current record in my AT table . However, when I test my script I get the error:

Error: Field "fldAjZqtaQu8IMl9F" cannot accept the provided value.

Below is the relevant section of myscript:

 

 

let imgURL = `https://mydomain.com/${ImgPath}`;
const table = base.getTable("Entries")
const query = await table.selectRecordsAsync({fields:["ImgPath", "PhotoURL"]})
let record = query.records[0].id;

await table.updateRecordAsync(record, {
    "PhotoURL": imgURL
})

 

I see plenty of examples where the update is triggered to batch update the entire table but I am hoping to do the update with each individual Webhook submission.

1 Solution

Accepted Solutions
Sho
11 - Venus
11 - Venus

 

I think this is fine if you just want to update automation records. Give it a try.

let inputConfig = input.config();
let hasImgPath = inputConfig.imgPath
let recID = inputConfig.recID;

if (hasImgPath !== null) {
    let imgURL = `https://mydomain.com/${hasImgPath}`;
    console.log(imgURL);

    const submissionsTable = base.getTable("Entries")
    await submissionsTable.updateRecordAsync( recID,
        {
            'PhotoURL': [{url:imgURL}]
        }
    );
} else {
    console.log('No image attachment');

 

See Solution in Thread

6 Replies 6

I don't know scripting so I can't help you there, but if you want an extremely easy no-code way of doing this, you can do this with Make's webhooks. No scripting nor coding required. Just have Make receive the webhook, and then do whatever you want to do in Airtable after that.

If you need help navigating the Make interface, I created this basic navigation video, along with some links to a few other Make resources.

Sho
11 - Venus
11 - Venus

Hi @mrcard ,

Each field has a different data type, so refer to the documentation.

multipleAttachments
Cell write format

TYPEDEF
Array<{
    url: string,
    filename?: string,
}>

Cell values & field options - Airtable Scripting

In the case of your script, it looks like this

await table.updateRecordAsync(record, {
    "PhotoURL" : [{url: imgURL}]
})

 

mrcard
4 - Data Explorer
4 - Data Explorer

Thank you Sho for your response. I am able to update the path now but unfortunately it is not on the current record being processed in the automation, rather the last record with an empty imgPath field.

How might I point it to the current record being processed by the automation?

Below is my script:

let inputConfig = input.config();
let hasImgPath = inputConfig.imgPath
let recID = inputConfig.recID;

if (hasImgPath !== null) {
    let imgURL = `https://mydomain.com/${hasImgPath}`;
    console.log(imgURL);

    const submissionsTable = base.getTable("Entries")
    const submissionsQuery = await submissionsTable.selectRecordsAsync({fields:["ImgPath", "PhotoURL"]})
    let record = submissionsQuery.records[0].id;

    console.log(`record:${record}`);

    await submissionsTable.updateRecordAsync( record,
    
        {
            'PhotoURL': [{url:imgURL}]
        }
    
    );

} else {
    console.log('No image attachment');
}

 

Sho
11 - Venus
11 - Venus

 

I think this is fine if you just want to update automation records. Give it a try.

let inputConfig = input.config();
let hasImgPath = inputConfig.imgPath
let recID = inputConfig.recID;

if (hasImgPath !== null) {
    let imgURL = `https://mydomain.com/${hasImgPath}`;
    console.log(imgURL);

    const submissionsTable = base.getTable("Entries")
    await submissionsTable.updateRecordAsync( recID,
        {
            'PhotoURL': [{url:imgURL}]
        }
    );
} else {
    console.log('No image attachment');

 

Thanks so much for your continued help. For some reason, the script is not finding the record as the ID that gets passed into the script is not the same as the record in the table:

My Table:

table.jpg

Script:

script.jpg

Automation:

automation.jpg

I also tried just using the ID (autonumbering) field to locate the record but for some reason that is not recognized by the script when including it in the Input variables.  

mrcard
4 - Data Explorer
4 - Data Explorer

Updated input variables to point to correct action steps and Sho's answer above is working. Thanks again!