Forum Discussion

Myko_P's avatar
Myko_P
Expert
7 years ago

How to change the date format only for the messages of registered authors?

Hi,
I am trying to make our community custom author component to change the date format only for registered authors messages, not for the anonymous. Got the following FreeMarker error:

 

Freemarker template 'author_custom' processing failed:
_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 an extended node+sequence+hash+string (org.apache.xerces.dom.ElementImpl wrapped into f.e.dom.ElementModel).
Right hand operand is a number (wrapper: f.t.SimpleNumber).
The blamed expression:
==> messageAuthorId gt 0  [in template "author_custom" at line 15, column 6]

----
FTL stack trace ("~" means nesting-related):
	- Failed at: #if messageAuthorId gt 0  [in template "author_custom" at line 15, column 1]
----

The main part of the custom author component code is the folowing:

 

<#if env.context.message.uniqueId gt 0>
<#assign messageAuthorId = rest("/messages/id/${env.context.message.uniqueId}/author").user.id />
<#assign messageAuthorLogin = rest("/messages/id/${env.context.message.uniqueId}/author").user.login />
<#assign badges = rest("/users/id/${messageAuthorId}/badges") />
<#assign badgesCount = badges.user_badges.user_badge?size />
<#assign avatarUrl = rest("/users/id/${messageAuthorId}/profiles/avatar/url").value />
<#assign kudosCount = rest("/users/id/${messageAuthorId}/kudos/received/count").value />
<#assign postCount = rest("/users/id/${messageAuthorId}/posts/count").value />
<#assign blogCount = rest("/users/id/${messageAuthorId}/posts/style/blog/count").value />
<#assign solutionCount = rest("/users/id/${messageAuthorId}/solutions/received/count").value />
<#assign rankingName = rest("users/id/${messageAuthorId}/ranking/name").value />
<#assign profileUrl = "/t5/user/viewprofilepage/user-id/${messageAuthorId}" />
<#assign profileLocation = restadmin("/users/id/${messageAuthorId}/profiles/name/location").value />
<#assign profileIP = restadmin("/users/id/${messageAuthorId}/settings/name/user.last_visit_ipaddress").value />
<#if messageAuthorId.user.id gt 0>
<#assign regDate = restadmin("/users/id/${messageAuthorId}/registration_time?restapi.response_style=view").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd.MM.yyyy") />
<#else>
</#if>

It looks like I am trying to compare incomparable data types. :robotembarrassed: But what exactly am I doing wrong? Thank you! 

  • Myko_P

    Check the updated code

    <#if env.context.message.uniqueId gt 0>
    <#assign messageAuthorId = rest("/messages/id/${env.context.message.uniqueId}/author").user.id />
    <#assign messageAuthorLogin = rest("/messages/id/${env.context.message.uniqueId}/author").user.login />
    <#assign badges = rest("/users/id/${messageAuthorId}/badges") />
    <#assign badgesCount = badges.user_badges.user_badge?size />
    <#assign avatarUrl = rest("/users/id/${messageAuthorId}/profiles/avatar/url").value />
    <#assign kudosCount = rest("/users/id/${messageAuthorId}/kudos/received/count").value />
    <#assign postCount = rest("/users/id/${messageAuthorId}/posts/count").value />
    <#assign blogCount = rest("/users/id/${messageAuthorId}/posts/style/blog/count").value />
    <#assign solutionCount = rest("/users/id/${messageAuthorId}/solutions/received/count").value />
    <#assign rankingName = rest("users/id/${messageAuthorId}/ranking/name").value />
    <#assign profileUrl = "/t5/user/viewprofilepage/user-id/${messageAuthorId}" />
    <#assign profileLocation = restadmin("/users/id/${messageAuthorId}/profiles/name/location").value />
    <#assign profileIP = restadmin("/users/id/${messageAuthorId}/settings/name/user.last_visit_ipaddress").value />
    <#if messageAuthorId?number &gt; 0>
    <#assign regDate = restadmin("/users/id/${messageAuthorId}/registration_time?restapi.response_style=view").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd.MM.yyyy") />
    <#else>
    </#if>

     You already fetched the id during rest call so you do not need to use messageAuthorId.user.id, you just need to use messageAuthorId and need to convert that id into number as well to make it compatible with the right-hand side.

     

  • Myko_P

    Check the updated code

    <#if env.context.message.uniqueId gt 0>
    <#assign messageAuthorId = rest("/messages/id/${env.context.message.uniqueId}/author").user.id />
    <#assign messageAuthorLogin = rest("/messages/id/${env.context.message.uniqueId}/author").user.login />
    <#assign badges = rest("/users/id/${messageAuthorId}/badges") />
    <#assign badgesCount = badges.user_badges.user_badge?size />
    <#assign avatarUrl = rest("/users/id/${messageAuthorId}/profiles/avatar/url").value />
    <#assign kudosCount = rest("/users/id/${messageAuthorId}/kudos/received/count").value />
    <#assign postCount = rest("/users/id/${messageAuthorId}/posts/count").value />
    <#assign blogCount = rest("/users/id/${messageAuthorId}/posts/style/blog/count").value />
    <#assign solutionCount = rest("/users/id/${messageAuthorId}/solutions/received/count").value />
    <#assign rankingName = rest("users/id/${messageAuthorId}/ranking/name").value />
    <#assign profileUrl = "/t5/user/viewprofilepage/user-id/${messageAuthorId}" />
    <#assign profileLocation = restadmin("/users/id/${messageAuthorId}/profiles/name/location").value />
    <#assign profileIP = restadmin("/users/id/${messageAuthorId}/settings/name/user.last_visit_ipaddress").value />
    <#if messageAuthorId?number &gt; 0>
    <#assign regDate = restadmin("/users/id/${messageAuthorId}/registration_time?restapi.response_style=view").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd.MM.yyyy") />
    <#else>
    </#if>

     You already fetched the id during rest call so you do not need to use messageAuthorId.user.id, you just need to use messageAuthorId and need to convert that id into number as well to make it compatible with the right-hand side.