Using FreeMarker to Work with Hidden Fields Used in Advanced Templates

Advanced printing templates can fail to print when they depend on a sublist hidden field.

In the following custom transaction form example, the Show box beside the Corporate Card field box is not checked. Therefore, Corporate Card is hidden from templates.

Advanced PDF/HTML Templates Custom Transaction Form page with the Corporate card box outlined in red on the Screen Fields > Expenses subtab.

When a field is visible (box is checked), it is represented as a Boolean condition in the advanced template, like this:

          <#if expense.corporatecreditcard == true>
   "Corporate Card" is checked!
</#if> 

        

When a field is hidden, you must instead compare the value of the field with a string: "T"(true) or "F"(false), like this:

          <#if expense.corparatecreditcard == "T">
   "Corporate Card" is checked!
</#if> 

        

A template that depends on the Corporate Card hidden field is no longer valid because the type of box changes from Boolean condition to string. You cannot compare a Boolean condition to a string.

If you use a string condition like the preceding example and then make the field visible, then this condition is not valid.

Error Messages

If a template cannot be printed because it depends on a sublist hidden field, you receive an error message similar to one of the following:

  • In this example from the template editor, the comparison of string with Boolean condition is not valid:

    Advanced PDF/HTML Templates sample error message where the comparison of string with boolean is not valid.
  • In the following example, the second condition is not valid because it cannot be evaluated to true or false:

    Template Editor Error Message

    Advanced PDF/HTML Templates sample error message where a condition cannot be evaluated to true or false.

    UI Error Message

    Advanced PDF/HTML Templates sample UI error message.

Solution for Unknown Visibility of the Field

You should avoid a scenario where a template depends on a sublist hidden field.

If you do not know whether the field is visible, you should create a condition in which the template behaves correctly in both cases, like in the following example.

            <#if (expense.corporatecreditcard?is_boolean && expense.corporatecreditcard) || (expense.corporatecreditcard?is_string && expense.corporatecreditcard == "T")>
   "Corporate Card" is checked!
</#if> 

          

Related Topics

General Notices