How to use NetSuite email plug-in scripts

Author: Karl Threadgold

 

While optimising our internal NetSuite system at Brovanture, it soon became apparent that we needed to be able to send out consulting engagement emails for the EPM and ERP projects that we work on. However, the slight complication of this was that we needed to have the approval status of the record updated automatically in NetSuite depending on the client’s response.

To implement this, my initial idea was to use the customer centre to allow the client to log in and update the record manually. Though pretty quickly, I realised that this process would not be especially user friendly for clients, so I set about finding other options.

To find a solution, I needed to expand my limited knowledge around NetSuite email plug-in scripts. The essential idea behind them is that an email is received into a NetSuite generated email address, which is then converted into an object where logic can be applied to the details on the email and as a result, actions performed within the NetSuite account.

The idea behind my process was to:

  • Create a custom record for ‘Engagement Letters’ which would have a number of custom fields relating to consulting engagement details to populate in an email
  • Send the consulting engagement email to the client via a workflow ‘send email’ action
  • The client would reply to the email and the logic behind their reply email would be used to update the approval status within NetSuite on the custom record.

After constructing the custom record, I set about creating the email template to send to the client. I did this by inputting text and entering in some CRMSDK tags to drag data from the record to populate the email, for example:

“Dear ${customrecord.custrecord_eng_client}” will pull through the client’s name.

The final part of the email consisted of the links to approve and reject the engagement. They are shown below:

 

Approval link

Accept the Engagement Letter

Rejection link

Reject the Engagement Letter

 

They are simply links to email addresses for the client to reply to, however crucially, there is a tag for the custom record ID (${customrecord.recordid}).

Once the client selects either the approve or reject link, their email client opens and the email address and subject default. The subject will default with the ID of the custom record as the link remembers that the email was sent from that particular record.

This takes me on to step three of the process – The email plug-in script. The logic behind the script will pick up the record ID and spot that it is either in the approved or rejected email address. It will then open the record and update the approval status, before saving the record.

Following this, alerts can be sent to internal employees once statuses have updated via saved searches, workflows or scripts.

The email plug-in script is detailed below:

function process(email){

//define variables by taking data from the email

var subject = email.getSubject();

var textbody = email.getTextBody();

var from = email.getFrom();

var to = email.getTo();

var internalid = parseInt(subject);

var approved = 2

var rejected = 3

var sentdate = email.getSentDate();

//update the engagement record approval status

var engagementrecord = nlapiLoadRecord('customrecord_engagement_letter', internalid);

nlapiLogExecution('DEBUG', 'engagementrecordid', engagementrecord);

engagementrecord.setFieldValue('custrecord_approval_status', approved);

engagementrecord.setFieldValue('custrecord_eng_send_email', 'F');

nlapiSubmitRecord(engagementrecord);

}

I’ve removed some nuances in the process I came across to make everything a little clearer. There are two scripts, one for the approval email address and one for the rejection email address. They are almost identical apart from the fact that they set the approval status to different options.

Customisation in NetSuite is quick to deploy, with functionality guaranteed after upgrades and can shape business processes very effectively.

 

Please feel free to get in touch if you would like any help with customising your NetSuite system or if you'd like to discuss anything else to do with how we could help with your business systems!

References: Veda Chalam Mahadevan and Joshua Meiri’s articles/comments on Linkedin about email plug-ins.