The client side MailMergeService allows running a mail merge against. The nice thing about using this library is it gives you access to pretty much everything the Write menu does and it incorporates validating the client has the Desktop Manager in place.
There are 2 primary variables to work with in dealing with this service.
- The Mail Merge Template’s PluginID
- The Contact ID
Lets take a look at a javascript function that accepts these two variables as string inputs and then runs a mail merge. There are other parameters withing the function, most are self-explanatory:
function DoMailMergeService(pluginId, contactId) {
require([‘Sage/MailMerge/Service’], function () {var contextSvc = Sage.Services.getService(‘ClientEntityContext’);
var context = contextSvc.getContext();
var contactId = context.EntityId;var oService = Sage.MailMerge.Helper.GetMailMergeService();
if (oService) {
var oMailMergeInfo = new oService.MailMergeInformation();
var strLiterature;
var iLiteratureCount;
oMailMergeInfo.BaseTable = ‘CONTACT’;
oMailMergeInfo.DoHistory = true;
oMailMergeInfo.EditAfter = true;
oMailMergeInfo.EditBefore = false;
oMailMergeInfo.DoAttachments = true;
oMailMergeInfo.AttachmentPath = Sage.MailMerge.Helper.MailMergeInfoStore().AttachmentPath; ;
oMailMergeInfo.LibraryPath = Sage.MailMerge.Helper.MailMergeInfoStore().LibraryPath;
oMailMergeInfo.FileDirectory = oService.MailMergeGUI().GetPersonalDataPath(); //Needed for otFile Output
oMailMergeInfo.MergeSilently = false;
oMailMergeInfo.TemplatePluginId = pluginId;
oMailMergeInfo.MergeWith = MergeWith.withEntityIds;
oMailMergeInfo.EntityIds = contactId;
oMailMergeInfo.OutputTo = OutputType.otFile; //otEmail //otFile //otFax //otPrinter;
oMailMergeInfo.UseTemplateDocProperties = false; // true;
oMailMergeInfo.ExecuteMailMerge();
}
});
}



