Help

Attachment automation to add and not replace attachment

Topic Labels: Automations
Solved
Jump to Solution
6605 11
cancel
Showing results for 
Search instead for 
Did you mean: 
Paul_Plume
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello,

I am trying to find a way to add an attachment from a new record to a field that already has one.
The automation deletes the existing file and add the new one.
I tried adding the URL from the search step in the automation as well as of the URL of the new attachment but it does not work. Also tried to separate them with ", " Or “;” but it does not work either.

Did anyone manage to do that ?

Best

Paul

1 Solution

Accepted Solutions
Kamille_Parks
16 - Uranus
16 - Uranus

I did exactly that and successfully appended two attachment fields together.
Screen Shot 2021-09-18 at 11.49.47 PM

Can you post a screenshot of your Automation error?

See Solution in Thread

11 Replies 11

Hi @Paul_Plume ,

Unfortunately when an automation puts a new value in a field actually it overwrites it so there is no possible way to do this.

If you are java script familiar you can make a script that will extend the record with the new input,
If you are on free plan and you don’t want to upgrade you can create a new field for your 2nd attachment and then a formula field like “Attachment 1 & Attachment 2”, this will put in the same sentence the link for each document separately.
If none of those work for you, I found this video but I didn’t test it…

I wish those work for you. :slightly_smiling_face:

Hi,
some time ago I wrote the script doing that. it merges both fields and remove doubles (defined by filename), wrote result to 1st.
you may adjust to you env and use.
fieldcheck may be removed if you don’t need it
i’m not able to help with that now, but it’s not hard.

const TABLE='your table'; 
const FIELDS={
    'doc1':'first_docs',
    'doc2':'second_docs'
}  //change fields here if you change them in table
let rootTable = base.getTable(TABLE);
let fieldCheck=(rootTable.fields).flatMap(field=>field.name).
        filter(field=>Object.values(FIELDS).includes(field)).length;
if (fieldCheck<2) throw new Error( // both fields should be present in table
    'Script '+Object.values(FIELDS).join('&')+' failed, check these fields');
let config = input.config();
let query = await rootTable.selectRecordsAsync()
let record = query.getRecord(config.recordId);
let doc1=record.getCellValue(FIELDS.doc1);
let doc2=record.getCellValue(FIELDS.doc2);
if (!(doc1&&doc2)) doc2=doc1||doc2; // if empty field, take other field
else{ //check to ignore duplicate docs
    doc1.forEach(doc=>
    doc2.flatMap(d_two=>d_two.filename).includes(doc.filename) ?
         doc1.pop():doc2.push(doc))
}
await rootTable.updateRecordAsync(record, {
    [FIELDS.doc1]:doc2
});

This is incorrect. All you have to do, usually, is insert the existing value, add a comma, and add the additional value that should be appended. This has always been the case since Automations were launched, and works for all editable fields not just attachments.

Kamille_Parks
16 - Uranus
16 - Uranus

I did exactly that and successfully appended two attachment fields together.
Screen Shot 2021-09-18 at 11.49.47 PM

Can you post a screenshot of your Automation error?

Hi @Kamille_Parks ,

I guess you are confused in the process we try to solve the requirement.

There is no ability for the automation to extend the field’s content because it actually updates it.!!! What you describe is it to keep somehow the previews value as a non updated value and then to import it with the new one in the same new filed that combines the two values. In this case we have two cons:

  1. The previous value is updatable
  2. In some cases the automation returns wrong

So I highly recommend to be more careful with your words you use and stay more close the the problem you try to solve by looking the most efficient way. :winking_face:

If I (a) didn’t already provide the OP with a screenshot showing exactly how to setup the solution that they themselves mentioned, and (b) didn’t have one of the highest number of solutions awarded here, I would take that advice with fewer grains of salt.

There are perhaps some scenarios where the original value is some unretrievable mystery before its fed into an Update Record step. The description given in this post is not one of those scenarios. The original value is known, the value to be appended is known. If it wouldn’t have worked I wouldn’t have suggested it. If it couldn’t have worked I wouldn’t have included the above screenshot of my test which I used to confirm my approach was viable.

Paul_Plume
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you all, I tried Kamille’s solution and it works.
However the test did not go through with an “invalid string” error. However once ran the automation worked perfectly.
Sans titre

Despite issue marked as solved, I would like to clarify some details, it may help to somebody in future.

Nope, it’s possible, but needs additional efforts
According to reference:

When updating an existing attachment cell value, the specified array will overwrite the current cell value. If you want to add a new attachment without deleting the current attachments, you can spread the current cell value…

To conclude:

  • attachment cell value is always array of attachments (e.g. [ x ] = x1,x2,x3…)
  • often that array includes single element X, but that’s still array
  • if you overwrite it with another field value, (array of Y), it’s OK
  • if you want to “extend the field’s content”, you need to add previous + new value and put into cell and here is the problem:
    table expects single array, like [x1,x2,x3,y1,y2…]
    Automation takes value from step1, adds values from step2 and puts it into new array to put in field.

Why test doesn’t work then??
if you press on A_Import, you should see something like:
image

I think, automation counts that “orphaned comma” as “unexpected end of array” and refuse to create it.
so, if automation runs on empty attachment field, or if it runs with zero “find record” result, it may fail.

if it’s okay, then it’s done

Otherwise, you can insert (after Find records) script step which takes step 1 and 2 results, and
if value 1 is empty, result = value 2
if value 2 is empty, result = value 1
if both are empty, result is empty
if both are not empty, result=value1+value2 (cocatenate 2 arrays)

in short, it may be smth like:
image

And then you may create next step “Update record” and use that value, “result”

P.S. later, you may encounter ‘duplicates issue’ when each automation run adds content and doesn’t check if it already exist in result field. Also, you can’t rely on ‘concat removing duplicates’ because similar attachemt in different field has different url.
Then you can turn it to smth like my script at the beginning :grinning:

Hi @Alexey_Gusev,

That’s really nice! Thanks for correcting me and sharing useful information :slightly_smiling_face:

Thanks.