This article is relevant if you are seeking to migrate your legacy NetSuite email and merge templates to the new scriptable format.
NetSuite had announced in 2015 that it is deprecating the use of the CRMSDK tags in place of the scriptable tags under the Freemarker template engine. ¬† However, the real impact of this is felt during the 2016.2 release. ¬†The CRMSDK tags will not render right and thus, you are forced to convert to get your content to look right.
Since most of the client work we do is for more complex matters, we haven’t really had to deal with simple template conversions. ¬†As many people know, we are experts with Freemarker and have developed a very powerful “Content Rendering Engine (CRE)” available to our clients to supercharge their NetSuite template production. ¬† Due the changes in 2016.2 release, we expect the NetSuite community is going to encounter a few issues. ¬† This article is meant to highlight some basic items that may come up.
Resolving Issues with Saving NetSuite Scriptable Templates
One issue we experienced with a converted template was with Freemarker’s built-in mechanism to round numbers. ¬†Since we were working with Bitcoin for our Bitcoin Transaction Coordinator, we need to have eight decimals of precision. ¬†Our basic CRMSDK email templates had no problem outputting the eight decimals. ¬†However, Freemarker wanted to round to four decimals without us asking our permission. ¬†To solve this, you use the Freemarker “built-in” modifier to express a number in “computer” fashion by simply qualifying the template variable with a “?c” suffix. ¬†However, when you do this, NetSuite may not allow you to save the template.
In this case, we ended up getting an error such as:
The template cannot be saved due to the following errors: customRecord.CUSTRECORD_BTC_TRX_QUANTITY_GROSS is not a number, it is com.netledger.templates.model.EmptyModel
To solve these types of challenges, which have to do with NetSuite’s datatype assumptions as ¬†they pre-parse the Freemarker template upon save, use a variable and test for a null situation. ¬†See the following template syntax which can be placed at the top of your template.¬†¬†When you want to reference the variable, do so this way:
<#assign amt=0> <#if customRecord.CUSTRECORD_BTC_TRX_QUANTITY_GROSS?has_content> <#assign amt=customRecord.CUSTRECORD_BTC_TRX_QUANTITY_GROSS> </#if>
Reference the value this way:
instead of this direct way:
Migrate Scripts to nlapiCreateEmailMerger
If you were previously using nlapiMergeRecord to produce merged templates, you will need to modify your code to use the new nlapiCreateEmailMerger function. Fortunately, the code is pretty easy. Here is a before and after.
mailMerge = nlapiMergeRecord(template, 'customrecord_btc_trx_request', Trx.id); nlapiSendEmail(emailFrom, emailName, mailMerge.getName(), mailMerge.getValue(), null, null, records, attachment);
mailMerge = nlapiCreateEmailMerger(template); mailMerge.setCustomRecord('customrecord_btc_trx_request', Trx.id); mailMergeResult = mailMerge.merge(); nlapiSendEmail(emailFrom, emailName, mailMergeResult.getSubject(), mailMergeResult.getBody(), null, null, records, attachment);
Get Expert NetSuite Help
If you are like me, you think the NetSuite platform really is space for innovation. If you want to work with professionals that can optimize your day-to-day NetSuite use while opening up new opportunities to generate revenue and lower costs, let’s have a conversation.