@akondewar In your code you fill efl
after executing mail merge with regions, so the table is filled before setting the SET
field. Please see the example provided above, where the SET
field is filled before executing mail merge with regions.
@alexey.noskov Thanks, it’s working for following condition
SET efl "{MERGEFIELD efl \* MERGEFORMAT}"}
SET supcs "{MERGEFIELD supcs \* MERGEFORMAT}"}
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
But while adding one more Compare then it’s not working, that is { COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" }
,
SET efl "{MERGEFIELD efl \* MERGEFORMAT}"}
SET supcs "{MERGEFIELD supcs \* MERGEFORMAT}"}
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
**{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" },**
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
@akondewar { MERGEFIELD isExclude \*MERGEFORMAT }
is also filled after executing mail merge with regions. That is why it does not work. You should use the same SET/REF fields approach for this field.
@alexey.noskov
Ok, but how it’s working fine while using following codtion without using SET REF for 'isExclude ’
SET efl "{MERGEFIELD efl \* MERGEFORMAT}"}
SET supcs "{MERGEFIELD supcs \* MERGEFORMAT}"}
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
Actually ‘isExclude’ value is present in the table row(input xml file).
I have attached Sample code and Word Template file.
Purchase Order TemplateV9.docx is working fine
Kindly check the code and template file
SampleCode_04-April-2024.zip (53.8 KB)
@akondewar As I can see everything works as expected with Purchase Order TemplateV9.docx
template and the following simple code:
Document doc = new Document("C:\\Temp\\Purchase Order TemplateV9.docx");
doc.getMailMerge().execute(new String[] { "efl","supcs" }, new String[]{ "true", "true" });
doc.updateFields();
DataSet ds = new DataSet();
ds.readXml("C:\\Temp\\input_v3.xml");
doc.getMailMerge().executeWithRegions(ds);
doc.save("C:\\Temp\\out.docx");
@alexey.noskov Yes I know,working fine for TemplateV9.docx. But its not working as espected for ‘Purchase Order TemplateV10.docx’
Condition in '‘Purchase Order TemplateV10.docx’ :
SET efl "{MERGEFIELD efl \* MERGEFORMAT}"}
SET supcs "{MERGEFIELD supcs \* MERGEFORMAT}"}
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
@akondewar As I have mentioned earlier AND
function accepts only two parameters. In your syntax, however, there are three parameters.
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" },
{ COMPARE "{REF efl }" = "true"})
}
Also, there cannot be situation when isExclude
field value simultaneously equals two different values.
@alexey.noskov Thanks,
Attached word templates is working fine while executing through eclipse, but not on Linux server (java version 1.7).
Purchase_Order_Template_v2.docx (Without SET,REF)
Purchase Order TemplateV9.docx( Using SET,REF)
Kindly do the needful.
Purchase_Order_Template_v2.zip (53.7 KB)
@akondewar Unfortunately, I do not see what can be done from our side. I can only suggest the flowing:
- Please make sure you are using the same templates, data, code and Aspose.Words version in both your test and production environments.
- Try simplifying the template and data to make it easier to debug.
- Try adding fields that shows the values passed to
SKIPIF
to make sure they are evaluated correctly.
@alexey.noskov Thanks for reply, I found the following RCA :
We are using multiple locales.
Following condition is not working while we set 'CurrentThreadSettings.setLocale(“pl_PL”) / de-AT etc.
It is working fine while locale is ‘en_US’
Our condition in the template :
SET efl "{MERGEFIELD efl \* MERGEFORMAT}"}
SET supcs "{MERGEFIELD supcs \* MERGEFORMAT}"}
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
@akondewar The provided condition is not quite correct. AND
function accepts only two parameters. In your syntax, however, there are three parameters.
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "7-Items Received" },
{ COMPARE "{REF efl }" = "true"})
}
Also, there cannot be situation when isExclude
field value simultaneously equals two different values. So this condition, even if there was not a syntax error, is always false
.
You can check this using the following simple field { =AND(1,0,1) }
this will return syntax error because AND
accepts only two parameters. { =AND(1,0) }
will return 0
, i.e. false
.
@alexey.noskov , My bad, actual condition is
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
This is working fine while we are setting CurrentThreadSettings.setLocale("en_US");
Not working or skipped condition while CurrentThreadSettings.setLocale("pl_PL");
@alexey.noskov , My bad, actual condition is
{ SKIPIF { = OR(
{ = AND(
{ COMPARE "{ MERGEFIELD isExclude \*MERGEFORMAT } = "8-All Line Items Received" },
{ COMPARE "{REF efl }" = "true"})
},
{ = AND(
{ COMPARE { MERGEFIELD closedshort } = "true" },
{ COMPARE { REF supcs } = "true" })
})
} > 0 }
This is working fine while we are CurrentThreadSettings.setLocale("en_US");
Not working or skipped condition while CurrentThreadSettings.setLocale("pl_PL");
@akondewar In pl_PL
locale coma is used as decimal separator so it cannot be used as a separator in OR
and AND
functions. The following syntax in pl_PL
locale will give syntax error { = AND(0,1) }
. You should use semicolon instead of coma when pl_PL
locale is used:
// Set locale for the current thread.
Locale current = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.forLanguageTag("pl-PL"));
DataTable dt = new DataTable("data");
dt.getColumns().add("isExclude");
dt.getColumns().add("closedshort");
dt.getColumns().add("test");
dt.getRows().add("true", "true", "1 This row will be excluded");
dt.getRows().add("false", "false", "2 This row will not be excluded");
dt.getRows().add("true", "true", "3 This row will be excluded");
dt.getRows().add("false", "false", "4 This row will not be excluded");
Document doc = new Document("C:\\Temp\\in.docx");
doc.getMailMerge().execute(new String[] { "elf", "supcs" }, new String[] { "true", "true" });
doc.updateFields();
doc.getMailMerge().executeWithRegions(dt);
doc.save("C:\\Temp\\out.docx");
// Restore locale.
CurrentThreadSettings.setLocale(current);
@alexey.noskov Thanks for the update.
Would you be able to provide us with a list of locales where semicolons are required instead of commas, so we will update technical document.
@akondewar You can use the following code to get decimal point symbol for current locale:
CurrentThreadSettings.setLocale(Locale.forLanguageTag("pl-PL"));
DecimalFormatSymbols symbols = new DecimalFormatSymbols(CurrentThreadSettings.getLocale());
System.out.println(symbols.getDecimalSeparator());
@alexey.noskov , We are using multiple custom templates.
As suggested by you we are using SET REF for this issue and made code change according this, and moved following code before ‘cleanupOptions’ , then it’s working fine for SET REF.
mapAditionalParam.put("efl", true);
mapAditionalParam.put("supcs", true);
mapAditionalParam.put("woordopid", "true");
mapAditionalParam.put("woorddmdid", "true");
mapAditionalParam.put("printattach", "true");
mapAditionalParam.put("printtasks", "true");
mapAditionalParam.put("printprocessnotes", "true");
mapAditionalParam.put("printwobarcode", "true");
But it not working if printwobarcode=true
and present in header as well as details section.
If I moved above code after merge.setCleanupOptions(cleanupOptions);
then it’s working.
Above change suggested by you for :
https://forum.aspose.com/t/how-to-update-dynamic-value-to-mergedfield-if-condition/278592/5
We want both template must be worked.
Sample code has been attached.
Forum.zip (146.4 KB)
@akondewar In your template there are two printwobarcode
merge field one inside region another outside the region. So here you should also use SET
/REF
fields. Since when you execute simple mail merge the filed outside the region is filled but the field inside the region is not filled. To fill the field inside region the printwobarcode
field must be in WODetails
data source. So this is exactly the same situation as described above.
@alexey.noskov we are supporting multiple locales, so requesting you can you share the list of locale that support ‘,’ and ‘;’ or other separator for nested formula field expression has an OR
function with arguments separated by comma (,
)
{ SKIPIF { = OR( { = AND( { COMPARE "{ MERGEFIELD isExclude *MERGEFORMAT } = “8-All Line Items Received” }, { COMPARE "{ MERGEFIELD isExclude *MERGEFORMAT } = “7-Items Received” }, { COMPARE “{REF efl }” = “true”}) }, { = AND( { COMPARE { MERGEFIELD closedshort } = “true” }, { COMPARE { REF supcs } = “true” }) }) } > 0 }
@akondewar There is no such list. You can use the following code to get decimal point symbol for current locale:
CurrentThreadSettings.setLocale(Locale.forLanguageTag("pl-PL"));
DecimalFormatSymbols symbols = new DecimalFormatSymbols(CurrentThreadSettings.getLocale());
System.out.println(symbols.getDecimalSeparator());