Hi Folks,
I have a simple workflow for contact, when a document is created for the contact i want to send an email to the contact using formula and want to attach the contact related document file into the email as attachment, any help will be much appreciated. below code that didn't work.
Many thanks
I have a simple workflow for contact, when a document is created for the contact i want to send an email to the contact using formula and want to attach the contact related document file into the email as attachment, any help will be much appreciated. below code that didn't work.
Code:
// Find document related to the contact $documentId = record\findRelatedOne('Contact', id, 'documents', 'createdAt', 'desc'); // get document name $documentName = record\attribute('Document', $documentId, 'name'); // Get the attachment for the given document $attachmentId = record\findOne('Attachment', 'relatedId', $documentId); // Prepare email body content $emailBody = string\concatenate( 'Please find attached required document', $documentName, '\n', 'Cheers', '\n' ); // Create email record $emailId = record\create('Email', 'to', entity\attribute('emailAddress'), 'status', 'Sending', 'subject', 'Required Document', 'body', $emailBody, 'isHtml', true, 'attachmentsIds', list($attachmentId) ); // Send email ext\email\send($emailId);
Comment