Georg Walther

Georg Walther

Wednesday, 11 November 2020 15:19

Workflow Email Skript

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:

 

  • Send email to more than one recipient 
  • Define one or more ‘Reply-to’ email address

 

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

 
 
 
 
 
Friday, 24 January 2020 16:15

Alta Via Mailchimp connector

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: 

Searching a solution that fits

  • Do we really need a middleware to facilitate the integration?
  • Is the price for the middleware justified for this purpose?
  • We just want to sync an email address, do we really have to configure a middleware and maintain it?
  • Our integration needs are very custom. All products on the market are either overkill or not what we need.
  • Make or buy? Should we just start to develop the integration ourselves?

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.

How does it work?

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.

  • The connector pushes new customers/email addresses to Mailchimp.
  • Mailchimp manages the double opt-in and sends out newsletters.
  • Subscription status changes are synced back from Mailchimp into NetSuite on demand.

In detail:

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:

  • Confirmed Opt-In (if the customer agreed to receive campaigns)
  • Soft Opt-In (if the customer can receive opt-in eMails)
  • Soft Opt-Out (if the customer can receive opt-in eMails)
  • Confirmed Opt-Out (the customer can neither receive campaign emails nor opt-in eMails)

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.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Friday, 31 May 2019 15:44

NetSuite's SFTP Module - N/sftp

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:

 

1) Alta Via has developed many SFTP integrations. Contact us if you like us to help you.

 

2) If you want to do this all by yourself, here are four steps you need to follow for a basic setup or test:

 

2.1) What do you need? Your checklist:

  • URL Address (host)
  • Port
  • Folder Name
  • Password
  • Host Key
  • Host Key type (one of these three: dsa, ecdsa, rsa )
  • GUID (Globally Unique Identifier)

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.

 

2.2) Host Key

In a Windows command shell or on a Mac in terminal, run this command:

ssh-keyscan -t rsa -p [port] [host]

 

2.3) GUID

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
        };
    }
);

 

2.4) Connection and transfer

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
        }
    }
);
Friday, 24 May 2019 09:56

Payment slip with reference number

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;
}​

CONTACT US!

O NetSuite SuiteCloudDeveloperNetwork rgb 2NetSuite SolutionProvider horiz rgb

NOTE! This site uses cookies and similar technologies.

If you not change browser settings, you agree to it.

I understand