```const template = render.mergeEmail({ templa...
# suitescript
c
Copy code
const template = render.mergeEmail({
    templateId: 37,
    transaction: {
        type: 'salesorder',
        id: transactionData.transactionId
    }
})
I'm trying to get sales order fields into an email template but the template is being sent without values. Does this code look correct?
e
const mergeResult = render.mergeEmail({
templateId: SCRIPT_PARAMETERS.EMAIL_TEMPLATE,
transactionId: recordId
});
This is what I have used before.
c
[ "Error", " at sendTemplatedEmail (/SuiteScripts/AutomatedEmails/cancellation_email_mr.js9333)", " at Object.reduce (/SuiteScripts/AutomatedEmails/cancellation_email_mr.js8121)" ]
Copy code
const template = render.mergeEmail({
    templateId: 37,
    transactionId: transactionData.transactionId
})
The docs are too light on info, they claim to use options.transactionId but then the example uses entity: { type: 'employee', id: senderId },
e
Review if your email template is for a transaction and if your
transactionData.transactionId
is a number and has a value. the example share is using a sales order and it is working perfectly. I'm working right now on the script that uses it. Zero issues.
c
No issue with transactionId Maybe it's the template record
image.png
I assume "Transaction" is correct.
e
Can you get this and log them?
const emailSubject = mergeResult.subject;
var emailBody = mergeResult.body;
Then, I would try to remove any expression and just see if a simple plain template works. I guess it si something wrong with the template.
c
emailBody logs out the HTML
emailSubject logs out the subject from the template record
Copy code
function sendTemplatedEmail(transactionData) {
    const senderId = 47165;
    const recipientEmail = transactionData.customerEmail;

    const template = render.mergeEmail({
        templateId: 37,
        transactionId: transactionData.transactionId
    })

    const emailSendOptions = {
        author: senderId,
        recipients: recipientEmail,
        subject: template.subject,
        body: template.body,
        relatedRecords: {
            transactionId: transactionData.transactionId
        }
    }

    email.send(emailSendOptions);
}
FYI: This is the entire function
Copy code
<p>Dear ${transaction.entity.firstname}</p>
Then these fields in the email are all empty
and I can verify those fields have values and the sales order ID is correct. i
Copy code
const template = render.mergeEmail({
    templateId: 37,
    transaction: {
        type: 'salesorder',
        id: transactionData.transactionId
    }
})
It sends with this though, but I'm using a transaction{} whereas you're not.
Very strange
e
We just have an URL and a field that I"m replacing on the code since I need scripting to access it. So I'm not good with the syntax on the template but I would try to access something easier like the transaction.id first.
const mergeResult = render.mergeEmail({
templateId: SCRIPT_PARAMETERS.EMAIL_TEMPLATE,
transactionId: recordId
});
const emailSubject = mergeResult.subject;
var emailBody = mergeResult.body;
emailModule.send({
author: SCRIPT_PARAMETERS.EMAIL_SENDER,
recipients: email,
subject: emailSubject,
body: emailBody
});
${transaction.entity}
and
${transaction.tranId}
should work. Well, really weird. Glad you made it work.
c
It doesn't work
the fields are empty on the email
I can get the email to send if I use slightly different syntax to yours but the fields are always empty. If I use the same syntax as you, I just get an error
Copy code
const template = render.mergeEmail({
            templateId: 37,
            transaction: {
                type: 'salesorder',
                id: transactionData.transactionId
            }
        })
No error with the above code, email template send, fields are empty
Copy code
const template = render.mergeEmail({
    templateId: 37,
    transactionID: transactionData.transactionId
})
Above code throws an error, no email sends.
e
I'm out of ideas. Try with another transaction id, just hard code it .
c
I think my working syntax doesn't actually work at all, looks like the transaction is being ignored. I think your syntax is correct and maybe there's an issue loading the SO.
Yeah.. hardcoding the transaction ID worked.. but my variable has the same ID!
Thanks for your help!!
Maybe I need to force the variable to be Number()
👍 1
e
NetSuite is the devil. I'm using TypeScript, so it is indeed a number and it warned me that it should be a number.
c
TS is so much better.
🤝 1
s
N/render is a bit funny with the transactionId parameter if it's a number as a string instead of an actual number. The same applies to the N/email module with senderId, recipientId and related record IDs Suggest you try this:
Copy code
const template = render.mergeEmail({
            templateId: 37,
            transactionId: Number(transactionData.transactionId)
        })