How to toggle data in the word template

@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);

in.docx (15.9 KB)
out.docx (11.4 KB)

@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());