Populating tables with MailMerge

Hello,
I am facing some difficulties trying to generate a word document displaying contacts information, specifically tables.
I use the following payload and word template:

{
  "Template": "01_SB_Template.docx",

  "Data": {
    "FirstName": "Adam",
    "LastName": "Jensen",
    "Contacts": [
      {
        "Name": "John Doe",
        "Email": "johndoe@example.com",
        "Phone": "123-456-7890"
      },
      {
        "Name": "Jane Smith",
        "Email": "janesmith@example.com",
        "Phone": "098-765-4321"
      },
      {
        "Name": "Emily Johnson",
        "Email": "emilyjohnson@example.com",
        "Phone": "555-555-5555"
      }
    ]
  }
}

I managed to generate the word document by calling the flowing endpoint “/words/01_SB_Template.docx/MailMerge”

The simple mergefields are populated poperly but not the table and I’m not sur what is missing:

Some help would be appreciated in this matter.
01_SB_Template.docx (13.0 KB)
Generated_Document.docx (10.2 KB)

@SofianeB You should use ExecuteWithRegions method to fill the regions with data. Please see our documentation for more information:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/#mail-merge-with-regions

1 Like

Thank you for your answer,
Unfortunately ExecuteWithRegions does not seems to work for me.
Is this method available through the Aspose.Cloud API ?
e.g. would the format of the enpoint be like “/words/01_SB_Template.docx/ExecuteWithRegions” ?

I’m using postman at the moment to try out Aspose capabilities (the end goal being to make these calls from Salesforce).

Ok, it seems the required format for the request is as follows /words/01_SB_Template.docx/MailMerge?withRegions=true (withRegions=true)
The table is genetated properly now.

Is there any documentation providing details about the use MailMerge with Aspose.cloud?
My use cases revolve around using Rest call in conjunction with Word template in order to generate documents.

@SofianeB

Yes, you need to set the withRegions property to true to populate table data in MailMrege API. Please check the following documentation for details.

1 Like

Hello,

I have the following word template with a table that contains conditions (If statements).
02_SeniorsListwithIf.docx (13.0 KB)

My goal is to display only the rows that verify the condition, unfortunately empty lines are displayed instead, alongside the proper data.
Result here: 00_Test.docx (10.8 KB)
The Json:

{
  "Data": [
    {
      "Employee": [
        {
          "Name": "Soma",
          "Age": 22,
          "Occupation": "Junior Consultant"
        },
        {
          "Name": "Ed",
          "Age": 23,
          "Occupation": "Junior Consultant"
        },
        {
          "Name": "Julian",
          "Age": 45,
          "Occupation": "Senior Consultant"
        },
        {
          "Name": "Sofiane",
          "Age": 25,
          "Occupation": "Senior Consultant"
        },
        {
          "Name": "Aruna",
          "Age": 22,
          "Occupation": "Confirmed Consultant"
        },
        {
          "Name": "Luffy",
          "Age": 23,
          "Occupation": "Confirmed Consultant"
        }
      ]
    }
  ]
}

My understanding is that this could be handled using the cleanup options of MailMerge (to remove these empty rows) but so far no success.

Is this use case manageable with Aspose?

@SofianeB

We are looking into the issue and will update you shortly.

@SofianeB

Yes, cleanup options should meet your requirements. It seems your template and data are different from your output document. Please share your sample template with conditions so we can investigate the issue and guide you accordingly.

Hello @tilal.ahmad,
The json I use is the following but it seems to be the same as my previous post*

{
  "Data": [
    {
      "Employee": [
        {
          "Name": "Soma",
          "Age": 22,
          "Occupation": "Junior Consultant"
        },
        {
          "Name": "Ed",
          "Age": 23,
          "Occupation": "Junior Consultant"
        },
        {
          "Name": "Julian",
          "Age": 45,
          "Occupation": "Senior Consultant"
        },
        {
          "Name": "Sofiane",
          "Age": 25,
          "Occupation": "Senior Consultant"
        },
        {
          "Name": "Aruna",
          "Age": 22,
          "Occupation": "Confirmed Consultant"
        },
        {
          "Name": "Luffy",
          "Age": 23,
          "Occupation": "Confirmed Consultant"
        }
      ]
    }
  ]
}

The output I have:
image.png (3.8 KB)

@SofianeB

We have noticed the issue and noticed that the cleanup option is not working. So I logged a ticket(WORDSCLOUD-2600) for further investigation and rectification. We will notify you as soon as it is resolved.

Thank you for logging the ticket.
Do you have an idea of the timeframe to expect for the fix?

@SofianeB

I am afraid we cannot share any timelines at the moment. We will be in a good position to share an ETA or workaround as soon as the issue investigation is completed.

@SofianeB

Please note the merge process in a nutshell:

  1. Replace MERGEFIELD with values.
  2. If UnusedRegions is set, remove unused regions.
  3. If UnusedFields is set, remove unused MERGEFIELDs.
  4. Apply other cleanup options to the document.

As you can see, your IF fields remain after cleanup. So each table cell is not empty and cannot be removed.

To fix the issue, you could use the SKIPIF field to filter records. If a record doesn’t match the SKIPIF condition, it is skipped. I attached the template following the approach using cleanup options(EmptyParagraphs,UnusedRegions,UnusedFields,RemoveEmptyTableRows,RemoveTitleRow,RemoveTitleRowInInnerTables); it will help you accomplish the task.
TemplateSkipIF.docx (13.3 KB)
SkipIF_output.Docx (10.3 KB)

Thank you @tilal.ahmad for the update.
The output in the exemple you provided is indeed what I’m looking for.
I will try this out.

1 Like

The issues you have found earlier (filed as WORDSCLOUD-2600) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John