DocX from Dynamic Template

Certified Senior Developer

I'm trying to use "DocX from Dynamic Template" smart service.Here, I am trying to execute the below condition in template.

[#if doc.project.condition = 1] true [#else] false [/#if]

But i'm getting the below error:-

freemarker.core._MiscTemplateException: Can't compare values of these types. Allowed comparisons are between two numbers, two strings, two dates, or two booleans.Left hand operand is a node+sequence+hash+string (org.apache.xerces.dom.DeferredElementNSImpl wrapped into f.e.dom.ElementModel).Right hand operand is a number (wrapper: f.t.SimpleNumber).The blamed expression:==> doc.project.condition = 1  [in template "fr.opensagres.xdocreport.document.docx.DocxReport@2484c608!word/document.xml" at line 4, column 715]The failing instruction:==> #if doc.project.condition = 1  [in template "fr.opensagres.xdocreport.document.docx.DocxReport@2484c608!word/document.xml" at line 4, column 710]

Has anyone encountered this error before ? 

 

Thanks in advance

  Discussion posts and replies are publicly visible

Parents
  • Hello Bestlinl,

    1) When you are using the plugin you have to declare the mergeFields in Word (I added some references at the bottom) by doing this you just can "Merge 1 field"

    I won't suggest  you to have multiple places of maintenance "If statements" But as a first choiceI would recomend to create an XML in appian and define all the tags and labels that you want, and in the rule you can decide if you will like to show or not the field.

    1.1) Create a rule to create the xml

    ------rule!someExpressionRule-----------

    ="<project>"&

    "<someTag "&

       "conditionString='"& if( someCDT.condition = 1 "true", "false" )&"'"

            &" />"

    ...

    & "</project>"

    Second option to make an xml easier to debug. Since the CDT is an XSD.

    Create a wrapper CDT with all the information you need then as part of the rule call the function toxml( with the namespace:””, format:false, name:”project”)

    This will create the xml as you need in the docx.

    -----------------

    1.2) when configuring the smart service you can call the rule to assign the field "Xml Data Model" "=rule!someExpressionRule(param1:pv!someCDT)"

    2) If you still want to do it in word. You just have to be careful how you implement it. I can suggest first do the test with a simpler scenario but I will try to explain you what is required to achieve this:

    2.1) Copy a field from the ADT word example in the new workd

    2.2) you will have to right click and select "edit field", you will get the a popup with multiple options.

    2.3) You will need to add the folowing :  «[#if k.@quantity == "100"]»is 100«[#else]»not 100«[/#if]»

    which contains 2 pasts of just text and 3 merge fields, here the details:

    * «[#if k.@quantity == "100"]» : this is a mergeField with "[#if k.@quantity == "100"]" in "Field Popup > Field Properties > Field Name"

    * is 100 : is just text, you can add format to it

    * «[#else]»: this is a mergeField with "[#else]" in "Field Popup > Field Properties > Field Name"

    * not 100 : is just text, you can add format to it

    * «[/#if]»: this is a mergeField with "[/#if]" in "Field Popup > Field Properties > Field Name"

    As a Note  This plugin was created using FreemarkerTemplateContextXML libraries.

    Please let me know if this works.

    References :

    About the MergeField:

    Mail merge: Insert Merge Field

    *

    FreemarkerTemplateContextXML Library

    *

    IF Expressions I am using

    *

  • Ohh After posting this whole explanation I noticed a difference with your statements, try to make the comparation as a String like this

    [#if doc.project.condition = "1" ] true [#else] false [/#if]

    Maybe this documentation can help you with the statements
    * freemarker.org/.../dgui_template_directives.html

    I was able to replicate your error:

    Exception in thread "main" fr.opensagres.xdocreport.core.XDocReportException: freemarker.core._MiscTemplateException: Can't compare values of these types. Allowed comparisons are between two numbers, two strings, two dates, or two booleans.
    Left hand operand is a node+sequence+hash+string (org.apache.xerces.dom.DeferredAttrNSImpl wrapped into f.e.dom.AttributeNodeModel).
    Right hand operand is a number (wrapper: f.t.SimpleNumber).
    The blamed expression:
    ==> k.@quantity == 100 [in template "fr.opensagres.xdocreport.document.docx.DocxReport@180bc464!word/document.xml" at line 4, column 13783]
  • 0
    Certified Senior Developer
    in reply to josep
    Thanks for the effort.
    Double quotes ("1") resolved the issue.
  • 0
    A Score Level 1
    in reply to josep

    Hi @josep,

    I am new to Docx Reporting script and struggling to place a if condition in one of our document template which is giving me the error.

    Below is the code snippet.

    [#if «${aa.title}» == "" ] «${aa.type}» [#else] «${aa.title}» [/#if]

    Please help me out.

    Thanks in advance.

Reply Children
No Data