MailMergeField renders placeholder instead of content when value is empty

Posted by: greg on 14 May 2024, 11:53 am EST

  • Posted 14 May 2024, 11:53 am EST - Updated 14 May 2024, 11:55 am EST

    We’re using the FormattedText control in an RDLX report in AR17.

    We’re using the MailMergeField functionality to dynamically compose the content of the field.

    For example, we want to display the FirstName field and optionally display the MiddleName field prefixed with a delimiter if the MiddleName field contains a value.

    We create two MailMergeFields. The first has its value set to the FIrstName field.

    =First([FirstName], "ReportData")

    The second has its value set to the following expression:

    =IIF(IsNothing(First([MiddleName], "ReportData")), "", " (" & First([MiddleName], "ReportData") & ")")

    Finally, we include the two merge fields in the html content of the control.

    <Body>
    <div>
    <span><%FirstNameMerge /%></span>
    <span><%MiddleNameMerge /%></span>
    </div>
    </Body>

    In general this approach seems to work. If the data contains a firstname and middlename then rendered output is

    FirstName (MiddleName)

    However the problem occurs if there is no middlename in the data. The output becomes:

    FirstName <%MiddleNameMerge/%>

    The problem seems to be that when a merge field value resolves to an empty string, the merge field placeholder is not replaced.

    If I change the middle name merge field expression to

    =IIF(IsNothing(First([MiddleName], "ReportData")), "xxx", " (" & First([MiddleName], "ReportData") & ")")

    Then the resulting output is

    FirstName xxx

    Is there a reason why merge fields cannot resolve to an empty string? Is this a bug in the merge field handling?

  • Posted 15 May 2024, 5:36 pm EST

    Hi Mark,

    We were able to replicate the issue on our end and have escalated the same to our development team with the Case ID: AR-33486. We’ll let you know of any updates regarding the same.

    Regards,

    Anand

  • Posted 16 May 2024, 3:28 pm EST

    Hi Greg,

    You can set the Mail Merge Field’s value to the expression ‘=iif([@MailMergeFieldValue]=“”," ",[@MailMergeFieldValue])’ and it should work as expected.

    Please find attached a sample implementing the same.

    Regards,

    Anand

    MailMergeReports.zip

  • Posted 16 May 2024, 3:37 pm EST

    Hi Anand,

    Thanks. While setting the value to a whitespace character does avoid the issue in this case, I think the handling of MailMergeFields should still be reviewed. In some situations it would be undesirable to have additional whitespace in the output.

    In my opinion the MailMergeField name placeholder should never appear in the output.

    Regards,

    Greg

  • Posted 16 May 2024, 10:02 pm EST

    Hi Greg,

    Yes, the developers have acknowledged this as a bug and a fix for the same is expected to be released with ActiveReports v18.1.

    Regards,

    Anand

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels