I'm writing a custom Web Script that returns the result of a query in JSON format.This is the Freemarker script I use to generate the JSON output:
<#assign x = 0>
{"recordsReturned":${search.itemsPerPage},
"totalRecords":${search.totalResults},
"startIndex":0,
"sort":null,
"dir":"asc",
"records":[
<#list search.results as row>
{"id":"${row.id}",
"name":"${row.name}",
"icon":"${row.icon16}",
"urlcontext":"${url.context}",
"description":"${row.properties.description}",
"author":"${row.properties.creator}"
}
<#assign x = x+ 1>
<#if x != search.itemsPerPage>
,
</#if>
</#list>
]
}
The problem is that sometimes the documents resulting from the search do not contain the description property (I don't know why…. this should be a default property of all documents contained in Alfresco), and this causes an exception in the execution of the Freemarker script:freemarker.core.InvalidReferenceException - Expression row.properties.description is undefined on line 15, column 34 in org/alfresco/repository/search/keywordsearch.get.json.ftl.
How can I avoid this error? Is there a way, in a Freemarker script, to check if a note property exist?