Apr 01, 2020 06:17 PM
I have registration forms that collect a digital signature. It imports into airtable as a url, like this: (https://s3.amazonaws.com/files.formstack.com/uploads/3669579/85172110/582992994/signature_85172110.p...)
Can someone help me with a script that would convert this to an image attachment?
Apr 03, 2020 04:22 PM
I’m not a developer, but I know a script - from a toolkit (paid plan, however) - that’ll fix you problem : https://miniextensions.com/convert-urls-to-attachments/ ( from miniextensions.com ).
Hope that’s helpful! :slightly_smiling_face:
Apr 07, 2020 02:11 PM
You can write a URL to an attachment field, like so:
// Change the names of this table/fields according to your base.
let submissionsTable = base.getTable('Form submissions');
let urlField = submissionsTable.getField('Signature URL');
let attachmentField = submissionsTable.getField('Signature attachment');
let submissionsQuery = await submissionsTable.selectRecordsAsync();
let updates = [];
for (let record of submissionsQuery.records) {
let url = record.getCellValue(urlField);
let attachments = record.getCellValue(attachmentField);
// If this record already has an attachment, skip it.
if (attachments !== null) {
continue;
}
// Otherwise, attach the image at the URL.
updates.push({
id: record.id,
fields: {
[attachmentField.id]: [{url: url}]
}
});
}
// Update records in batches of 50.
while (updates.length > 0) {
await submissionsTable.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
Apr 08, 2020 08:32 AM
Thanks Stephen! This is fantastic
Apr 08, 2020 08:46 AM
Glad to hear you find this snippet helpful! One minor revision — my original post was missing await
in the last section of the script. I’ve updated it.
Apr 09, 2020 01:03 PM
Hi Stephen,
I am getting an error :frowning:
What am I doing wrong?
Apr 09, 2020 01:28 PM
This script assumes that the URLs are always filled. To handle this case, try replacing lines 13-15 with the following:
if (url === null || attachments !== null) {
continue;
}
This will tell the script to skip records without anything in the W1 field.
Let me know if this works!
Apr 09, 2020 01:53 PM
Hi Stephen,
Thank you for the quick response.
It’s not working :frowning: - see attached.
What do you think is wrong?
Apr 09, 2020 01:55 PM
I think the condition needs to be if (url === null || attachments !== null) {
In other words, skip it if the URL is blank, or if there are already attachments.
Apr 09, 2020 02:01 PM
Hi Kasra,
Thank you for you answer.
It seems to “pass” but now it is showing a new error (see attached) - what’s wrong?