1

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

Reply

null

Content aside

  • 1 Likes
  • 13 hrs agoLast active
  • 8Views
  • 1 Following