Is there any reason why my dynamic placeholders in...
# suitescript
l
Is there any reason why my dynamic placeholders in the email template are being returned as blank by this code snippet? I used ${transaction.tranid} in the email template (ID 12) for example.
Copy code
var mergeResult = render.mergeEmail({
                        templateId: 12
                    });
             
                if (emailAddresses.length > 0) {
                    email.send({
                        author: runtime.getCurrentUser().id,
                        recipients: emailAddresses.join(','),
                        body: mergeResult.body,
                        subject: mergeResult.subject,
                        relatedRecords: {
                            transactionId: journalEntry.id
                        }
                    });
                }
a
your
render.mergeEmail
should have another parameter passing in the record id, for a transaction that parameter would be
transactionId
Copy code
var mergeResult = render.mergeEmail({
                        templateId: 12
                        transactionId: id
                    });
you're passing the JE id in as a related record for the email.send, but I'm guessing its not related but is the base record? the relatedRecords is for OTHER records than the main one for the template
so you can pass in the entity, or something else in addition to the (in your case) JE
actually I just reviewed the API docs, and what I said above isn't explicitly what the docs say, they don't say I'm wrong either though, so I guess try it and see if it works ¯\_(ツ)_/¯
Copy code
var mergeResult = render.mergeEmail({
                        templateId: 12,
                        transactionId: journalEntry.id
                    });
             
                if (emailAddresses.length > 0) {
                    email.send({
                        author: runtime.getCurrentUser().id,
                        recipients: emailAddresses.join(','),
                        body: mergeResult.body,
                        subject: mergeResult.subject
                    });
                }
t
relatedRecords on email.send only attaches the email to the record so you can see it in the records emails. it has nothing to do with the the email template merge using render.mergeEmail. @Anthony OConnor sample code should work
a
thank you, I was questioning my sanity over here 😄
l
Thank you. That worked! Is it correct to say that if a transaction does not have a Messages sublist like a Journal Entry then I won't be able to attach the email to it? Or how will I know which transactions support email message linking?