Emailing a set of child attachments
I thought I'd post the code that I came up with, as I struggled to get all the syntax correct and couldn't find a decent example of how to go about it.
I have a quality system and I wanted to send an email with all the latest forms attached, per site and by frequency (weekly or monthly). I created a parent record and linked the child records to it. I then wanted a button to copy all the documents attached to the children into the parent record, and then send all of those in a single email. Here's the code
let a := this;
for b in files(a) do
removeFile(b)
end;
let c := 1;
for d in ChildTable do
if d.ImageField then
let imgUrl := shareFile(d.ImageField);
let fileName := "File" + c + ".pdf";
importFile(p, imgUrl, fileName)
end;
c := c + 1
end;
sendEmail({
from: userEmail(),
to: p.'Email List',
subject: "Quality Documents",
text: "Please find your Quality Documents attached.",
html: "",
attachments: files(p)
})
It was the combination of shareFile and importFile that I struggled with. Got there in the end!
Regards John
1 reply
-
Hi John
I really like your approach to this.
I am changing they way I do customers jobs, from a single job per record to multi jobs and will need an order acknowledgement for the whole all Order (header and child records) but will also need a separate despatch notification as each child order is sent out). but need these to be shown on the main records after sending and deleted from the child). I can use a variation of your script to add the child attachments one by one as goods go out.
Like it - it's neat 👍
Content aside
-
1
Likes
- 4 hrs agoLast active
- 1Replies
- 19Views
-
2
Following
