Tip 3: Use dynamic value while sending email using email template in Netsuite and attach the email to record

Isn’t it a common requirement to use recipient’s name in an email?????…

Of course… YES….

So in Netsuite, when we use email template, we can set some standard field which represents the recipient’s name.

But when we have a requirement to use only First Name of the recipient(say customer’s first name) to greet in the email, we can’t use any standard field available in email template.

So here comes a simple solution to this: 🙂

In the email temple use any name(in CAPITAL letter) prefixed with NL like NLCUSTOMERFIRSTNAME whereever you want to replace with dynamic name.

Now in script write something like this:


function SendEmailToCustomer (recipientEmail, customerFullName, customerId) {
//Get Customer First Name
var firstName = (customerFullName.indexOf(‘ ‘) != -1) ?   customerFullName.split(‘ ‘)[0] : customerFullName;

//create object that contains mapping of custom tag to value & insert a value for Non-Native Tag “NLCUSTOMERFIRSTNAME
var dynamicReplaceParam = new Array();
dynamicReplaceParam[‘NLCUSTOMERFIRSTNAME ‘] = firstName;

//Merge with Email template with Job Applicant record
var emailMergeObj = nlapiMergeRecord(emailTemplateID, ‘customer’, customerId, null, null, dynamicReplaceParam);

/*Send Email using Values from merged object
merged objects’ getName() will return Subject you set on the Email template record
merged objects’ getValue() will returned Message body that has all dynamic values replaced by merge process*/
nlapiSendEmail(sender, recipientEmail, emailMergeObj.getName(), emailMergeObj.getValue(), null, null, null, null);
}


customerId, you can use to attach the email to Customer Record.

Important:

A small note to add: If you want to add the email to recipient’s record, then add InternalID of a single entity in recipient, so that it will automatically attached to the entity record. For more details refer SuiteScript Developer Guide –  “nlapiSendEmail(author, recipient, subject, body, cc, bcc, records,
attachments, notifySenderOnBounce, internalOnly)”

Please share your thoughts if you have something interesting to say related to this….

Thanks

Asha

Advertisements

One thought on “Tip 3: Use dynamic value while sending email using email template in Netsuite and attach the email to record

  1. Attractive part of content. I just stumbled upon your web site and in accession capital to say that I get actually enjoyed account
    your weblog posts. Any way I will be subscribing to your feeds and even I fulfillment you get entry to constantly rapidly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s