Rules in mail merge are not working

Hi,

I am trying to merge data into the document based on mail merge rules.
For example:

Ask, Fill-In,Set Bookmark,Skip Record If ,Next Record If ,Next Record.

The rules are not working when i am trying to merge the data into the document.

i am using Aspose 10.4.0 jdk 1.5 ,java 1.5 and office 2003 & 2007.

I have also attached the template for Reference.

can any one please help me on this?

Thanks,
Rajesh

Hi
Thanks for your request. I cannot reproduce the problem on my side. I tested with dummy data and as I can see IF, NEXT, NEXTIF fields used in your template works as expected.
Could you please provide us a code that will allow us to reproduce the problem? We will check the issue and provide you more information.
Best regards,

Hi Alexey,

Thanks For your Quick Reply. Here is the code below i am using .

Document doc = new Document("C:\Template\MailMerge.doc");
String[] fields = {
    "FolderRSN",
    "FolderYear",
    "FolderType",
    "FolderSection",
    "FolderSequence"
};
String[] values = {
    "123456",
    "05",
    "B",
    "22",
    "110559"
};
doc.getMailMerge().execute(fields, values);
doc.save("C:\Temp\out_put.doc");

And also i am attaching the template(“mailrules.doc”) where i have used the rules Ask, Fill-In,Set Bookmark.

I have tried the rules with the same code and the rules were not working.

Advance Thanks,
Rajesh

Hi Rajesh,

Thanks for your inquiry.

Please note that Aspose.Words does support Ask/Fill-in fields upon field update process. But since these are not MergeFields that is why upon executing MailMerge, data from data source is not getting merged. For a list of fields supported during update, please visit the following link:
https://docs.aspose.com/words/java/update-field/

However, you can achieve the functionality of Fill-in fields after reading the thread suggested below:
<a href="Word Merge Fields during mail merge

Please let us know if you need more information, we are always glad to help you.

Best Regards,

Hi awais,

Thanks For your Quick reply . The example link you have provided for fillin is .net ,can you please provide any sample example for java.

Advance Thanks,
Rajesh

Hi
Thanks for your request. Here is the same code in Java:

// Open document
Document doc = new Document("C:\\Temp\\in.doc");
// Create DocuentBuilder. It will help us to modify fields
DocumentBuilder builder = new DocumentBuilder(doc);
// Get collection of FieldStart nodes
NodeCollection<FieldStart> starts = doc.getChildNodes(NodeType.FIELD_START, true);
// loop through all field starts and search for FILLIN fields
for (FieldStart start : starts)
{
    if (start.getFieldType() == FieldType.FIELD_FILL_IN)
    {
        // Every field in MS Word document consists of FieldStart, FieldSeparator, FieldEnd nodes
        // And Runs that represent field code and field value (displayed text)
        // If you need to change value of fillin field, you should change field code
        // And field value
        Node fieldSeparator;
        Node fieldEnd;
        // We should get field code and field value
        String fieldCode = "";
        String fieldValue = "";
        Node currentNode = start.getNextSibling();
        // Get Field code
        while (currentNode.getNodeType() != NodeType.FIELD_SEPARATOR)
        {
            if (currentNode.getNodeType() == NodeType.RUN)
                fieldCode += ((Run)currentNode).getText();
            currentNode = currentNode.getNextSibling();
            currentNode.getPreviousSibling().remove();
        }
        fieldSeparator = currentNode;
        currentNode = currentNode.getNextSibling();
        // Get field value
        while (currentNode.getNodeType() != NodeType.FIELD_END)
        {
            if (currentNode.getNodeType() == NodeType.RUN)
                fieldValue += ((Run)currentNode).getText();
            currentNode = currentNode.getNextSibling();
            currentNode.getPreviousSibling().remove();
        }
        fieldEnd = currentNode;
        // We should get question and answer from fillin field code
        Pattern regex = Pattern.compile("\\s*FILLIN\\s+\"([^\"]+)\"\\s+\\\\d\\s+\"([^\"]+)\"");
        Matcher matcher = regex.matcher(fieldCode);
        matcher.find();
        System.out.println(fieldCode);
        System.out.println(matcher.group(1));
        System.out.println(matcher.group(2));
        // Change field code and field value
        if (matcher.group(1).equals("What is your name?"))
        {
            fieldCode = fieldCode.replace(matcher.group(2), "Alexey");
            fieldValue = "Alexey";
        }
        // Insert new field code and field value
        builder.moveTo(fieldSeparator);
        builder.write(fieldCode);
        builder.moveTo(fieldEnd);
        builder.write(fieldValue);
    }
}
// save output document
doc.save("C:\\Temp\\out.doc");

Hope this helps.
Best regards,

Hi,

Thanks for your valuable reply.

I had used the above code to generate the document. The content i.e. fieldValue is getting merged with fill-in place holder in the document.

I am expecting that, Fill-in or Ask pop up should come up and get the input from user.

Is it possible to get the input from the user, at run time?. (i mean while opening the generated document and merge)

Hi
Rajesh,

Thanks for your request. I regret to share with you that Aspose.Words does not provide the requested feature. You have to take the input from user against the Fill-in fields manually once the document is saved by using Aspose.Words.

If we can help you with anything else, please feel free to ask.

Best Regards,