0

Send mail with attachments from different tables

Hi !

I would like to know how can I send by email, as an attachment, the documents for lines 29, 40 and 51?

The "Documents" table is not linked in N:1

---
Générer les textes
---;
let nomFacture := "Facture n°" + 'N° de transaction' + ".pdf";
let nomAnnexe := "Annexe à la facture n°" + 'N° de transaction' + ".pdf";
let nomJustifPaiement := "Justificatif de paiement de la facture n°" + 'N° de transaction' + ".pdf";
let FormulationMail := "Bonjour " + Compte.'Prénom' +
",<br><br>Veuillez trouver ci-jointe votre facture.<br><br>" +
Entreprise.'Signature des emails';
let ObjetMail := "Votre facture n°" + 'N° de transaction';
---
Enregistrer l'échange
---;
let me := this;
let newRecEchange := (create 'Échanges');
newRecEchange.(Compte := me.Compte);
newRecEchange.('Type de contact' := 2);
newRecEchange.('Canal de contact' := 2);
newRecEchange.(Type := 6);
newRecEchange.(Titre := ObjetMail);
newRecEchange.(Commentaires := FormulationMail);
---
Ajouter la facture en pièces jointes à l'échange
---;
let AddDocFacture := (create Documents);
AddDocFacture.('Échanges' := newRecEchange);
AddDocFacture.(Compte := me.Compte);
AddDocFacture.('Activités' := me.'Activités');
AddDocFacture.(Document := importFile(this, printAndSaveRecord(me, "Facture_template_dynamique"), nomAnnexe));
AddDocFacture.('Nom du document' := nomFacture);
AddDocFacture.('Type de document' := 5);
AddDocFacture.('Date de création' := today());
---
Ajouter l'annexe en pièces jointes à l'échange
---;
let AddDocAnnexe := (create Documents);
AddDocAnnexe.('Échanges' := newRecEchange);
AddDocAnnexe.(Compte := me.Compte);
AddDocAnnexe.('Activités' := me.'Activités');
AddDocAnnexe.(Document := importFile(this, printAndSaveRecord(me, "Annexe_facture_template_dynamique"), nomAnnexe));
AddDocAnnexe.('Nom du document' := nomAnnexe);
AddDocAnnexe.('Type de document' := 5);
AddDocAnnexe.('Date de création' := today());
---
Ajouter le justificatif de paiement en pièces jointes à l'échange
---;
let AddDocJustifPaiement := (create Documents);
AddDocJustifPaiement.('Échanges' := newRecEchange);
AddDocJustifPaiement.(Compte := me.Compte);
AddDocJustifPaiement.('Activités' := me.'Activités');
AddDocJustifPaiement.(Document := importFile(this, printAndSaveRecord(me, "Paiement_facture_template_dynamique"), nomJustifPaiement));
AddDocJustifPaiement.('Nom du document' := nomJustifPaiement);
AddDocJustifPaiement.('Type de document' := 5);
AddDocJustifPaiement.('Date de création' := today());
---
Envoyer par email
---;
sendEmail({
from: "test@mail.fr",
to: Compte.'E-mail principal',
cc: Compte.'E-mail secondaire',
subject: ObjetMail,
text: FormulationMail,
html: FormulationMail,
attachments: [Line29, Line40, Line51]
})

Thanks !

6 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 11 mths ago
    • Reported - view

    You can select attachments from another table like this:

    let attachment := first((select Tablex).attachmentfield)

    see https://forum.ninox.com/t/x2h7fm9/send-emails-with-pictures-in-the-body-and-also-with-attachments-of-your-choice for an example database.

      • Créateur de bien-être
      • Sebastien_Guillet
      • 11 mths ago
      • Reported - view

      RoSoft_Steven Thanks for your feedback. My difficulty is to recover the documents that I have just created (line 25, 36 and 47). Based on your formula, when can I tell him that I would like these to be the documents of the 3 recordings that I have just created?

      I was already inspired by your example database for emails. Thank you for this superb work!

      • Ninox partner
      • RoSoft_Steven.1
      • 11 mths ago
      • Reported - view

      Sébastien Guillet 

      I think someting like :

      let att1 := record(Documents,number(AddDocFacture).Document;
      let att2 := record(Documents,number(AddDocAnnexe).Document;
      let att3 := record(Documents,number(AddDocJustifPaiement).Document;
      let att := [att1,att2,att3]
      ....
      attachments: att
      })
      

      Or another example:

      let att1 := first((select Documents where number(Id) = number(AddDocFacture)).Document;
      let att2 := first((select Documents where number(Id) = number(AddDocAnnexe)).Document;
      let att3 := first((select Documents where number(Id) = number(AddDocJustifPaiement)).Document;
      let att := [att1,att2,att3]
      ....
      attachments: att
      })
      
    • Créateur de bien-être
    • Sebastien_Guillet
    • 11 mths ago
    • Reported - view

    I again need help attaching attachments to an email.

    For some emails, I have documents in image fields that I manage to integrate without any problem.

    For other emails, I retrieve all documents from 1:N related records.

    On the other hand, I can't manage to attach both documents by retrieving them directly in an image field AND all the documents of the linked records.

    let attCGV := if 'Modèle'.CGV then
                Compte.Entreprise.'Conditions Générales de Vente'
            end;
    let attDonnees := if 'Modèle'.'Données personnelles' then
                Compte.Entreprise.'Traitement des données personnelles'
            end;
    let attSante := if 'Modèle'.'Données de santé' then
                Compte.Entreprise.'Traitement des données de santé'
            end;
    let attDocs := 'Documents 1:N'.Document;
    let attTotal := [attCGV, attDonnees, attSante, attDocs];
    sendEmail({
        from: Expediteur,
        to: 'Destinataire principal',
        cc: 'Destinataire en copie',
        bcc: 'Destinataire en copie cachée',
        subject: Sujet,
        text: 'Résumé',
        html: Commentaires,
        attachments: attTotal
    });
    'Envoyé' := true
    

    In this example of a button intended to send an email with attachments, attCGV, attData and attSante correspond to documents retrieved from image fields‧

    attDocs matches all documents in image fields for 1:N related records

    It does not seem possible, with this method, to take into account attCGV + attDonnees + attSante + attDocs because the result does not give the same type of data...

    Is there a way around this?

      • Ninox partner
      • RoSoft_Steven.1
      • 11 mths ago
      • Reported - view

       The attachments should be an array, can you try :

      let attTotal := array(attCGV,attDonnees,attSante,attDocs);

      • Créateur de bien-être
      • Sebastien_Guillet
      • 11 mths ago
      • Reported - view

       It works perfectly! THANKS

Content aside

  • Status Answered
  • 11 mths agoLast active
  • 6Replies
  • 179Views
  • 2 Following