AnsweredAssumed Answered

JSON - Can't convert the date to string

Question asked by bengrah on Nov 12, 2012
Latest reply on Feb 25, 2013 by muralidharand
Hi all,

This is what I suspect, a very easy issue to solve. I just can't see what I'm doing wrong here.

I've got a webscript which has some JSON on the front end:

<#assign loopNumber = 0 />

<#escape x as jsonUtils.encodeJSONString(x)>
{
   "recentDocs": [
      <#list results as recentDocItem>
         {
            "document-name":"${recentDocItem.properties["cm:name"]}",
            "document-location":"${recentDocItem.displayPath}",
            "document-modified":"${recentDocItem.properties["cm:modified"]?datetime}"
         <#if loopNumber < 9>
         },
         <#else>
         }
         </#if>
         
         <#assign loopNumber = loopNumber + 1 />
      </#list>
   ]
}
</#escape>

I'm becoming unstuck when getting the date:
"document-modified":"${recentDocItem.properties["cm:modified"]?datetime}"

I just want to get the date modified of a node and display it in one of my JSON values, but every time I do I get the following error:

 org.springframework.extensions.webscripts.WebScriptException: 10120061 Wrapped Exception (with status template): 10122344 Error during processing of the template 'Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.'. Please contact your system administrator.
   at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1047)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:400)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:462)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:500)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:316)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:372)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
   at java.lang.Thread.run(Thread.java:662)
Caused by: org.alfresco.service.cmr.repository.TemplateException: 10122344 Error during processing of the template 'Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.'. Please contact your system administrator.
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:206)
   at org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:876)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
   … 25 more
Caused by: freemarker.template.TemplateModelException: Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.<format> or ?string(format) built-in with this date.
   at freemarker.core.Environment.formatDate(Environment.java:776)
   at freemarker.core.Expression.getStringValue(Expression.java:105)
   at freemarker.core.Expression.getStringValue(Expression.java:93)
   at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.MixedContent.accept(MixedContent.java:92)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
   at freemarker.core.Environment.visit(Environment.java:428)
   at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.MixedContent.accept(MixedContent.java:92)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.EscapeBlock.accept(EscapeBlock.java:84)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.MixedContent.accept(MixedContent.java:92)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.Environment.process(Environment.java:199)
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:202)
   … 28 more



Any ideas?

Thanks,
Ben.

Outcomes