Calculate SUM, AVG and SUB in Mail Merge Template using Aspose.Words Cloud SDK for Node.js

I am facing issues with merging field. I am using mail merge template which I have created and passing the JSON data .Here my test folder test 2.zip (9.7 KB)
I want to calculate sum or other functions by combining values of two fields. I couldnt find any solution anywhere. This is for nodejs.

@yogibittint

Thanks for your inquiry. We are looking into your requirement and will update you shortly.

any solution, sir ?

@yogibittint

Please find updated template along with the output. I have amended your template, hopefully it will help you to accomplish the task.sumMergeField.zip (18.6 KB)

Please provide proper syntax or solution, so that i can implement the same.

@yogibittint,

Please elaborate, what issue are you facing with the above shared template? Sum is working fine in the mailmerge operation.

Sir, can you please share snippets for implementing Arithmetic operation in Aspose word cloud. Such as SUM(), AVG(). For eg. SUM({{value1}},{{value2}}) using Mail Merge/Mustache Template.

@yogibittint,

Thanks for your feedback. Please find sample code snippet and templatesumMergeField.zip (9.7 KB), hopefully it will help you to accomplish the task.

const { WordsApi, PostExecuteTemplateRequest } = require("asposewordscloud");

wordsApi = new WordsApi("xxxxx-xxxx-xxxx-xxxxx-xxxxx", "xxxxxxxxxxxxxxxxxxxxx");
var StorageApi = require("asposestoragecloud");
storageApi = new StorageApi({ appSid: "xxxxxxxx-xxxx-xxxxx-xxxx", apiKey: "xxxxxxxxxxxxxxxxxx", baseURI: "https://api.aspose.cloud/v1.1" });
var fs = require('fs');

const templateLocalPath = "sumMergeField.docx";
const dataLocalPath = "C:/Temp/demoData2.json";
const remoteFileName = "sumMergeField_output.docx";

// Upload File
storageApi.PutCreate(templateLocalPath, null, null, templateLocalPath, (responseMessage) => {
console.log("Uploaded File");    
                    });
// MailMerge Template
var request = new PostExecuteTemplateRequest();
request.name = templateLocalPath;
request.data = fs.readFileSync(dataLocalPath, "utf8");
request.destFileName=remoteFileName;
                       

wordsApi.postExecuteTemplate(request).then((result) => {    
    console.log(result.body.code);    
}).catch(function(err) {
    // Deal with an error
    console.log(err);
});

@yogibittint

As an update please note since Aspose.Words Cloud 19.4, we have released API Version V4.0. In addition to other improvements, it includes its own Storage API method for storage operations and we combined Mail Merge and Mustache template APIs. Now a single API is used for both types of templates. Please check the sample Node.js code for reference and feel free for any further assistance.

const { WordsApi, UploadFileRequest, ExecuteMailMergeRequest } = require("asposewordscloud");
var fs = require('fs');

// Please get your App Key and App SID from https://dashboard.aspose.cloud/#/apps.
wordsApi = new WordsApi("xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx");

const localFile = "C:/Temp/SampleMailMergeTemplate.docx";
const dataFile = "C:/Temp/SampleMailMergeTemplateData.txt";
const localDataFile = fs.readFileSync(dataFile, 'utf8');

const remoteFileName = "TestExecuteMailMerge.docx";
const resultFileName = "MailMerge_output.docx";
const remoteFolder = "Temp";

//Upload File
const uploadRequest = new UploadFileRequest({
		fileContent: fs.createReadStream(localFile),
		path: remoteFolder + "/" + remoteFileName
});


wordsApi.uploadFile(uploadRequest).then((resultApi) => {
		console.log('uploaded...');	
		}).catch(function(err) {
		// Deal with an error
		console.log(err);
});


//Mail Merge
const request = new ExecuteMailMergeRequest({
        name: remoteFileName,
        data: localDataFile,
        folder: remoteFolder,
        withRegions: false,
        destFileName: remoteFolder + "/" + remoteFileName
});
                       

wordsApi.executeMailMerge(request).then((result) => {    
		console.log(result.body);   
		console.log('Completed...');	
		}).catch(function(err) {
		// Deal with an error
		console.log(err);
});