emailMerger.setEntity() Seems to be not merging the used template with the entity

222 views Asked by At

I'm trying to send a template mail(scriptable) on user event to a customer in my sandbox and below is my code :

var emailMerger = nlapiCreateEmailMerger('22');
emailMerger.setEntity('customer', customerId);
 // emailMerger.setRecipient('customer', customerId);
var mergeResult = emailMerger.merge();
var emailSubject = mergeResult.getSubject();
var emailBody = mergeResult.getBody();


emailBody = emailBody.replace('{1}', name);
emailBody = emailBody.replace('{2}', date);

nlapiSendEmail('20', '[email protected]', 'Test Mail',emailBody, null, null, null, null);

But unfortunately, I'm unable to see any mail merged under the communication tab in that customer. Is anything I'm missing here ?

1

There are 1 answers

0
Prem Ranjan On BEST ANSWER
var obj = nlapiLoadFile(9398);
var records = new Object();
records['entity'] = '1752';
nlapiSendEmail('-5', '-5', 'emailSubject','emailBody', null, null, records, [obj]);

this will work mail and attachment will save in communication tab.