Aspose.Word IF FieldCode

Hi I downloaded Aspose.Words and tried out the free trial version.
I created a word document checking for Gender as
IF{MERGEFIELD Gender}="Male" "Mr" "Mrs/Ms"

I passed the parameter through the program.
But it gives the error Error! Unknown op
code for conditional.

Please Let me know how to use this.

Hi

Thanks for your inquiry. Could you please attach your document here for testing? I will check the problem on my side and provide you more information.
Best regards,

Please find the attached file.

I just added the parameters and their respective values.

Regards,
George

Hi

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed. The problem occurs because there should be white spaces before and after comparison operator
{ IF { MERGEFIELD Gender } = "Male" "Mr" "Mrs" }
Best regards,

Thanks for the Help!Andrey Noskov

It worked Fine.

Regards,
George

I am also evaluating the trial of your product. I am seeing the same problem as the original poster, however, my expression does have white space before and after the comparison operator. My example essentially looks like the one above, except I am outputting symbols instead of Mr./Mrs.

I have attached the word doc and sample data file. This works just fine in word but I see “unknown op code for conditional” when I run the mail merge through Aspose.

I found the problem. For future reference, it seems that you have to enclose the merge field in double-quotes so that it looks something like this:

{ IF "{ MERGEFIELD name }" = "value" "Option1" "Option2" }

I’m not sure if this is absolutely necessary, since I didn’t see it in any of the examples I found online, but it seems to work.

Hi,
The problem might occur if the merge field’s value is an empty string. It has been fixed in the current codebase, so you won’t experience it anymore starting with Aspose.Words 7.1 that is going to be released in a few weeks.
Thanks.

Hi,

I have another issue with the IF field. I use it to add line feeds if a field exists. For example:

{ IF "{ MERGEFIELD f2 \* MERGEFORMAT}" = "" "" "f2: { MERGEFIELD f2 \* MERGEFORMAT }" \* MERGEFORMAT}{IF "{ MERGEFIELD f3 \* MERGEFORMAT }" = "" ""f3: { MERGEFIELD f3 \* MERGEFORMAT}" \* MERGEFORMAT}

There is a line break that is included in the ‘else’ part. This does not appear when the document is merged.

I have attached an example doc, source code below.

Regards,

D

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Reflection;

namespace TDAsposeWordTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttontest1repeatingfields_Click(object sender, EventArgs e)
        {
            string thedir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string fn = Path.Combine(thedir, "test1.doc");
            string fno = Path.Combine(thedir, "test1.pdf");

            Aspose.Words.Document d = new Aspose.Words.Document(fn);
            d.MailMerge.ExecuteWithRegions(dtrows());
            d.MailMerge.Execute(dtheader());
            d.SaveToPdf(fno);
        }

        private void buttonTest2Linefeeds_Click(object sender, EventArgs e)
        {

        }

        DataTable dtheader()
        {
            DataTable dt = new DataTable("Header");
            System.Data.DataRow datarow;
            dt.Columns.Add("ADDR_1");
            dt.Columns.Add("ADDR_2");
            dt.Columns.Add("f1");
            dt.Columns.Add("f2");
            dt.Columns.Add("f3");
            datarow = dt.NewRow();
            datarow[0] = "Addr1";
            datarow[1] = "Addr2";
            datarow[2] = "f1";
            datarow[3] = "f2";
            datarow[4] = "f3";
            dt.Rows.Add(datarow);

            return dt;

        }

        DataTable dtrows()
        {
            DataTable dt = new DataTable("Lines");
            System.Data.DataRow datarow;
            dt.Columns.Add("ADDR_1");
            dt.Columns.Add("ADDR_2");
            dt.Columns.Add("f1");
            dt.Columns.Add("f2");
            dt.Columns.Add("f3");

            datarow = dt.NewRow();
            datarow[0] = "Addr1";
            datarow[1] = "Addr2";
            datarow[2] = "f1";
            datarow[3] = "f2";
            datarow[4] = "f3";

            dt.Rows.Add(datarow);
            datarow = dt.NewRow();
            datarow[0] = "Addr1";
            datarow[1] = "Addr2";
            datarow[2] = "line2-1";
            datarow[3] = "";
            datarow[4] = "";

            dt.Rows.Add(datarow);
            datarow = dt.NewRow();
            datarow[0] = "Addr1";
            datarow[1] = "Addr2";
            datarow[2] = "";
            datarow[3] = "line3-2";
            datarow[4] = "";

            dt.Rows.Add(datarow);
            return dt;

        }
    }
}

Hi

Thank you for additional information. I managed to reproduce the problem on my side. You will be notified as soon as it is resolved.
As a workaround, you can try using line break (Shift+Enter) instead of Paragraph break.
Best regards.

The issues you have found earlier (filed as 10628) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(83)

Hi,

The resolution of 10628 does not seem to fix the issue I thought this post related to. In the example, there should have been a paragraph break between f2 and f3. This does not appear to work after 8.0.0.0 has been installed. The work-around (to use shift-return and create a soft break) does in both 7 and 8.

Regards,

Doug

Hi

Thanks for your request. The Issue that you mean is still unresolved. You will be notified as soon as it is fixed. The issue 10628 related to conditional expressions without white space.
Best regards,

You mention that the problem with empty strings in the mergefield has been fixed. However I am using version 8.0.0.0 and this still does not work:

IF "{ MERGEFIELD mymergefield }" <> "" "some text" ""

It always will show “some text” wether the mergefield is empty or not.

Testing agains non-empty strings works correctly:

IF "{ MERGEFIELD mymergefield }" <> "some value" "some text" ""

Hi
Thank you for additional information. I managed to reproduce the problem with empty values of mergefields. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
Best regards.

Good day Andrew, we’ ve got almost same problem with double qoutes. When merging field like this:
if "{Mergefield М1}" <> "1" "Text1" "Text2"
In case, when М1 is empty we’ ve got next result:
if """" <> "1" "Text1" "Text2"

And we see in the merged document: <>
instead of Text1 or Text2.
It seems that you put double qoutes in empty mergefields.
Thanks in advance.

Hi

Thanks for your request. This problem is already resolved in the current codebase. The fix will be included into the next hotfix, which will be released in few weeks.
Best regards,

The issues you have found earlier (filed as 12052;11154) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.