Looking for MailMerge template and JSON example of array within individual pages

Hello! Imagine a scenario where a rental business wants to create a letter for each customer listing the movies they have out for rental.

JSON
{
“customers”: [
{ “Name”: “Peiter”, “ID”: “1”, “Movie”: [{“Name”: “History”},{“Name”: “Comedy”} ] },
{ “Name”: “Jan”, “ID”: “2”, “Movie”: [{“Name”: “Cooking”},{“Name”: “Horror”} ] },
{ “Name”: “Sophie”, “ID”: “3”, “Movie”:[{“Name”: “SciFi”},{“Name”: “Gaming”} ] }
]
}
template
Name: «Name»
ID: «ID»
Movies:
«foreach»
«[item.movie_name]»
«/foreach»

I’ve tried the above in the online demo without success. Creating the template manually using the MergeField insert.

@vcannon

We are looking at your template and data. We will share our findings with you shortly.

@vcannon

It looks like your template related issue. I have tested the scenario using the following template without any issues. Please attach your template document to the post. It will help us to investigate and guide you exactly.

Template_MailMerge_Test.docx (18.3 KB)

Thank you, Tilal, for your efforts and response.

We are using Ruby SDK for AsposeWordsCloud::ExecuteMailMergeOnlineRequest and testing using Aspose Demo https://products.aspose.app/words/mailmerge to test. I could not get the template you sent to work with the JSON in that online demo.

What API or demo did you use to verify?

@vcannon

Previously, I have tested the scenario using ExecuteMailMergeOnline API method of Aspose.Words Cloud SDK for .NET. However, it is working as expected using the Aspose.Words Cloud SDK for Ruby. Please check the sample code for your reference.
TestExecuteTemplate_out.docx (13.8 KB)

require 'aspose_words_cloud'

class Document

  include AsposeWordsCloud

  # Get App key and App SID from https://dashboard.aspose.cloud/
  APP_KEY = "xxxxxxxxxxxxxxxxxxxxxxx"
  APP_SID = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
  FILE_PATH = "C:/Temp/MailMergeSamples/"

  def initialize
    AsposeWordsCloud.configure do |config|
      config.client_data['ClientId'] = APP_SID
      config.client_data['ClientSecret'] = APP_KEY
	  end
    @words_api = WordsApi.new
  end

  # MailMerge
  def execute_mailmerge_online
      local_document_file = 'Template_MailMerge_Test.docx'
	  local_data_file = 'Template_MailMerge_TestData.json'
	  

	  output_file = 'TestExecuteTemplate_out.docx'
	  request_data = File.read(FILE_PATH + local_data_file)

    
      

      request_template = File.open(FILE_PATH + local_document_file)
      
      request = ExecuteMailMergeOnlineRequest.new(template: request_template, data: request_data, with_regions: true)

      result = @words_api.execute_mail_merge_online(request)
	  File.open(FILE_PATH + output_file, 'wb').write(result)
      puts "MailMerge Completed......"	  
end
end
	
	


document = Document.new()
puts document.execute_mailmerge_online

5 posts were split to a new topic: Microsoft Word Document MailMerge not working