Free Support Forum - aspose.cloud

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