Advanced “Send Email” Workflow action
‘Reply-to’ email address in NetSuite’s native Workflow action can not be set. You can define a ‘Send-from’ a ‘CC and a ‘BCC’ email address as well as only one recipient. This is sufficient in many situations, but some of our customer’s need more features.
Features we added to the standard functionality:
Our consultants can install the script in any account and then go ahead to configure the workflow action according to customer’s needs.
This screenshot shows the fields you can set:
If you like our support, feel invited to vet in touch with us.
Kind regards,
Georg Walther
Mailchimp is one of the most popular email newsletter tools on the market.
The usability is very much appreciated by many marketing managers around the world.
Naturally we are looking for ways to transfer data from NetSuite to MailChimp.
Common questions we have when we look for options to integrate:
Here, Alta Via has developed a simple approach. No middleware is needed. Only the email address is pushed from NetSuite to Mailchimp and then synced going forward.
The solution is very basic but customizable to the needs of our customers.
In this process, NetSuite is considered to be the leading system for master data (customer’s email address), whereas the email newsletter subscription status is managed in mailchimp.
After installation and configuration of the bundle, and as a first step you need to define your relevant customers, which shall become part of campaigns in mailchimp, through a saved search. The definition is important, as your customer data is precious and you might not want to share all of them.
The name of that search has to be entered in the general settings of your NetSuite account.
Note: Not all customers that you defined to be relevant will be replicated, but only the ones that have the appropriate opt-in status.
NetSuite has four status for email newsletters:
Your relevant customers then can be synchronized to the mailchimp account. If the status is one of Soft Opt-In or Soft Opt-Out then the customer email is synced to mailchimp in the status of "pending", meaning that the customer will receive an email from mailchimp to subscribe to a campaign.
If the customer opted-in (Confirmed Opt-In), then the customer’s email is synced to mailchimp in the status of "subscribed", so no additional subscription email will be sent to the customer.
Note: Still in all mailchimp emails you should ensure that the customer can unsubscribe from a campaign.
Customers are added as members to the configured mailchimp member list.
When customer synchronization is started, then NetSuite also reads the subscription status of the customer in mailchimp. If the customer unsubscribed, this status is also stored in the NetSuite system for information.
Note: Subscription status in NetSuite might not be up to date with the status in mailchimp, only after re-syncing the data is up to date.
With NetSuite's SuiteScript 2.0 you have the ability to access ssh servers, commonly known as secure FTP or SFTP.
You can upload or download files from an SFTP server. It is not possible to send files to NetSuite using the SFTP module. If you are looking for that, you can use a RESTLet.
If you are sure, SFTP is the answer to your question, we have a little bit of help for you here:
While URL, Port, Folder name and password are relatively easy to get (just ask the administrator of the service), you might not easily get the host key.
In a Windows command shell or on a Mac in terminal, run this command:
ssh-keyscan -t rsa -p [port] [host]
This is a unique identifier which the SFTP Module needs to create a connection with the remote server. Just copy the script below and enter the internal ID of the script which will later handle the connection and the domain. (restrictToScriptIds and restrictToDomains). Deploy it as a SuiteLet and run it through the link you find in the deployment.
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/log'],
function (serverWidget, log) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({
title: 'Guid Form'
});
form.addField({
id: 'username',
type: serverWidget.FieldType.TEXT,
label: 'Username'
});
form.addCredentialField({
id: 'password',
label: 'Password',
restrictToScriptIds: 'customscript_internal_id',
restrictToDomains: 'host of service'
});
form.addSubmitButton({
label: 'Submit Button'
});
context.response.writePage(form);
return;
} else {
var requset = context.request;
var myPwdGuid = requset.parameters.password;
log.debug("myPwdGuid", myPwdGuid);
context.response.write(myPwdGuid);
}
}
return {
onRequest: onRequest
};
}
);
The second script handles sending your file to the remote server. This is a workflow action script. You can modify it to be a module and pass sftp credentials and a file.
/**
*@NApiVersion 2.x
*@NScriptType WorkflowActionScript
*/
define(['N/sftp', 'N/file', 'N/search'],
function (sftp, file, search) {
function onAction(context) {
var txn = context.newRecord;
try {
var myPwdGuid = "WHAT YOUR SUITELET CREATED";
var myHostKey = "WHAT YOU FOUND FROM SSH-KEYSCAN";
var connection = sftp.createConnection({
username: 'YOUR USERNAME',
passwordGuid: myPwdGuid,
url: 'SERVICE DOMAIN',
port: PORT OF SERVICE IS USUALLY 22,
directory: 'FOLDER',
hostKey: myHostKey
});
var uploadFile = file.load({
id: 'PATH TO SOME FILE'
});
connection.upload({
filename: fileName,
file: uploadFile,
replaceExisting: true
});
}
}
return {
onAction: onAction
}
}
);
In Switzerland it is common to send a payment slip with the invoice.
in german: https://de.wikipedia.org/wiki/Einzahlungsschein_mit_Referenznummer
How this is done in NetSuite:
With a "Workflow Action Script" the "payment slip" is printed out on the invoice. A separate Advanced HTML template is filled with the data from the invoice and saved with the transaction record. NetSuite also offers the option to send this "payment slip" as a PDF by email together with the invoice.
Alta Via Consulting has developed a bundle for Switzerland that contains this payment slip and other localizations. Contact us for more details.
Script that creates the PDF:
function createPdf(rec) {
var renderer;
var pdf;
var recObj = getDataObject(rec);
renderer = render.create();
renderer.setTemplateByScriptId('CUSTTMPL_AV_ZAHLSCHEIN'); // Load the template CUSTTMPL_AV_ZAHLSCHEIN 125
renderer.addCustomDataSource({
format: render.DataSource.JSON, // Expecting an object
alias: 'record',
data: JSON.stringify(recObj).replace(/&/g, '&')
});
pdf = renderer.renderAsPdf()
return pdf;
}
In order to provide the "Payment slip with reference number" in NetSuite, a check digit must be calculated (among other things). This happens recursively according to "modulo10":
function mod10(bb) {
var R1 = 0;
var alg = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];
var be = bb.split("");
var bl = bb.length;
var Rbb;
var P1;
for (i = 0; i < bl; i++)
{
Rbb = parseInt(R1) + parseInt(be[i])
R1 = alg[Rbb % 10]
}
P1 = (10 - R1) % 10
return P1;
}
Hello,
We found that sending an email from a standard netsuite transaction does not allow us to modify the reply-to email address. Receipients are confused or do not reply to the email we want to. Here is a workflow action script which fixes this.
NetSuite has an enhancement request, which is currently not in progress. Enhancement # - 76077
var CONST = {
author_license: [some user id],
replyTo: 'set this or pull it from somewhere',
bcc: 'whatever you wish'
}
function sendEmail_WF() {
var po = nlapiGetNewRecord();
var emailMerger = nlapiCreateEmailMerger(yourFormId);
emailMerger.setTransaction(po.getId());
emailMerger.setEntity('vendor', po.getFieldValue('entity'));
var mergeResult = emailMerger.merge();
var subject = mergeResult.getSubject();
var body = mergeResult.getBody();
var recipient = getReceipients(po.getFieldValue('entity'));
if (recipient.length == 0) {
throw 'There is no email address to send this email to.';
}
var attachments = [];
attachments = getAttachment(attachments, po);
attachments = getPDF(attachments, po);
var records = {
transaction: po.getId()
}
if (recipient && recipient != '') {
nlapiSendEmail(CONST.author_license, recipient, subject, body, null, CONST.bcc, records, attachments, null, null, CONST.replyTo);
}
}
function getReceipients(vendId) {
// Here we pull email addresses from the vendor's contacts and also addd the vendor's main email address
var recipient = [];
recipient.push(nlapiLookupField('entity', vendId, 'email'));
var cS = nlapiSearchRecord("contact", null,
[
["company", "anyof", vendId],
"AND",
["custentity_is_po_recipient", "is", "T"],
"AND",
["email", "isnotempty", ""]
]
);
for (var i = 0; cS && i < cS.length; i++) {
recipient.push(cS[i].getId());
}
var recipientNoDupe = [];
recipient.forEach(function (recipient) {
if (recipientNoDupe.indexOf(recipient) < 0) {
recipientNoDupe.push(recipient);
}
});
return recipientNoDupe;
}
function getAttachment(attachments, po) {
varcustbody_your_document_field = po.getFieldValue('custbody_your_document_field');
if (custbody_your_document_field && custbody_your_document_field != '') {
attachments.push(nlapiLoadFile(custbody_your_document_field));
}
return attachments;
}
function getPDF(attachments, po) {
var paras = [];
paras.formnumber = 'your transaction form id';
var file = nlapiPrintRecord('TRANSACTION', po.getId(), 'PDF', paras);
attachments.push(file);
return attachments;
}