cancel
Showing results for 
Search instead for 
Did you mean: 

Association properties in json.ftl

nikhilaraballi
Champ in-the-making
Champ in-the-making
How to get properties of association object using json.ftl?


I have a type abc:appDate.  It has a property abc:dateTime an association to self ie.,

    <association name="abc:nextAppDate">
    <title>Next App Date</title>
    <source>
       <mandatory>false</mandatory>
       <many>false</many>
    </source>
    <target>
       <class>abc:appDate</class>
       <mandatory>false</mandatory>
       <many>true</many>
    </target>
    </association>

I was trying to get properties of association as below, but getting "Error during processing of the template 'Expression result.assocs[\"abc:nextAppDate\"] is undefined"

    <#macro dateFormat date>${date?string("dd MMM yyyy")}</#macro>
        <#escape x as jsonUtils.encodeJSONString(x)>
        {
           "nodeRef": "${result.nodeRef}",   
           "date": "<@dateFormat result.properties["abc:dateTime"] />",
            "nextDate": [
          <#list result.assocs["abc:nextAppDate"] as childKey>
          {
          "date": "<@dateFormat childKey.properties["abc:dateTime"] />"            
          }
          <#if child_has_next>,</#if>
           </#list>
          ]
        }
        </#escape>
1 REPLY 1

nikhilaraballi
Champ in-the-making
Champ in-the-making
Actually the code needed a null check. The following code is working

    <#macro dateFormat date>${date?string("dd MMM yyyy")}</#macro>
        <#escape x as jsonUtils.encodeJSONString(x)>
        {
            "nodeRef": "${result.nodeRef}",
            "date": "<@dateFormat result.properties["abc:dateTime"] />",
            "nextDate": [
            <#if (result.assocs["abc:nextAppDate"])??>
            <#list result.assocs["abc:nextAppDate"] as childKey>
            {
            "date": "<@dateFormat childKey.properties["abc:dateTime"] />"              
            }
            <#if child_has_next>,</#if>
            </#list>
            <#else>
       </#if>
            ]
        }
        </#escape>
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.