ANS-0569 · SUITESCRIPT DEVELOPMENT

How to Use render.emailMerge in NetSuite Map/Reduce Scripts Effectively?

Discover the crucial parameter type requirement for render.emailMerge to function correctly in NetSuite server-side scripts like Map/Reduce.

Short answer

To successfully use render.emailMerge in NetSuite server-side scripts such as Map/Reduce, ensure that the templateId and entity.id parameters are cast as numbers using parseInt(). Passing these values as strings will prevent the function from executing correctly, leading to unexpected behavior.

Scenario

NetSuite developers attempting to utilize the render.emailMerge function within server-side scripts, such as Map/Reduce, may encounter unexpected failures. Despite initial assumptions, the function is indeed compatible with these script types. The root cause of the issue often lies in how parameters are passed to the function.

Solution

To ensure render.emailMerge executes successfully in NetSuite server-side scripts, it is essential to cast the templateId and entity.id parameters as numbers. The function will not accept these parameters if they are passed as strings.This will NOT work:

var emailMergeResult  render.mergeEmail({templateId: emailTemplateInternalId,entity: {type: 'customer',id: customerInternalId}});

This WILL work:

var emailMergeResult  render.mergeEmail({templateId: parseInt(emailTemplateInternalId,0),entity: {type: 'customer',id: parseInt(customerInternalId,0)}});

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant