Sep 18, 2021 12:34 AM
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
Solved! Go to Solution.
Sep 18, 2021 11:50 PM
I did exactly that and successfully appended two attachment fields together.
Can you post a screenshot of your Automation error?
Sep 18, 2021 01:04 AM
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:
Sep 18, 2021 10:30 AM
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
});
Sep 18, 2021 11:42 PM
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.
Sep 18, 2021 11:50 PM
I did exactly that and successfully appended two attachment fields together.
Can you post a screenshot of your Automation error?
Sep 19, 2021 01:56 AM
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:
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:
Sep 19, 2021 07:57 AM
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.
Sep 21, 2021 12:45 AM
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.
Sep 21, 2021 07:45 AM
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:
Why test doesn’t work then??
if you press on A_Import, you should see something like:
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:
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:
Sep 21, 2021 08:11 AM
Hi @Alexey_Gusev,
That’s really nice! Thanks for correcting me and sharing useful information :slightly_smiling_face:
Thanks.