Forum Discussion

Inactive User's avatar
Inactive User
6 years ago

Discussions Reply: How to get parent's timezone using API or context objects

We've created a "posted in reply to" function for our forum replies so that users can easily click on it to see the original post. However, I'm having timezone(?) or original post time issues. The time is shown in the CURRENT user's timezone, not the timezone of the original post. Any ideas?

Live example:  https😕/community.jmp.com/t5/Discussions/Random-Uniform-keeps-giving-me-the-same-number/m-p/189066#M40772

Screenshot:

Code:

<#-- check to see if we have a message -->
<#if env.context.message?? && env.context.message.uniqueId gt 0>

<#assign root = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/root?restapi.response_style=view").message> <#-- get that message from rest -->

<#assign parent = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/parent?restapi.response_style=view").message> <#-- get the parent message from rest -->


<#if parent.@null[0]?? && parent.@null=="true"> <#-- check to make sure a parent exists -->

<#-- if no parent you can put some text here or nothing -->
<#else>
<#--<div class="reply-to-stamp">-->

<span class="reply-author">
&nbsp;|&nbsp;&nbsp;Posted in reply to <a href="${parent.@view_href}" title="Message from ${parent.post_time.@view_date}">message from ${parent.author.login} ${parent.post_time.@view_friendly_date?replace('-','/')} ${parent.post_time.@view_time}</a></span>
<#--</div>-->
</#if> <#-- end parent check -->
</#if> <#-- end message context check -->

 

  • Inactive User's avatar
    Inactive User
    6 years ago

    After trying a bunch of freemarker sorcery, I just decided to take a straight line and query the parent for its datetime. 

    <#-- check to see if we have a message -->
    <#if env.context.message?? && env.context.message.uniqueId gt 0>

    <#assign root = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/root?restapi.response_style=view").message> <#-- get that message from rest -->

    <#assign parent = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/parent?restapi.response_style=view").message> <#-- get the parent message from rest -->


    <#if page.context.thread?? && page.context.thread.topicMessage??>
    <#assign apiVersion = "2.0"/>
    <#assign parentTimeQ = "SELECT post_time FROM messages WHERE id='${page.context.thread.topicMessage.uniqueId?string.computer}'"/>
    <#assign parentTime = restadmin(apiVersion, "/search?q=" + parentTimeQ?url + "&restapi.response_style=view").data.items![] />
    <#assign parentTimeString = parentTime[0].post_time />
    <#else>
    <#assign parentTimeString = ''/>
    </#if>

    <#if parent.@null[0]?? && parent.@null=="true"> <#-- check to make sure a parent exists -->

    <#-- if no parent you can put some text here or nothing -->
    <#else>
    <#--<div class="reply-to-stamp">-->

    <span class = "reply-author">
    &nbsp;|&nbsp;&nbsp;Posted in reply to <a href = "${parent.@view_href}" title = "Message from ${parent.post_time.@view_date}">message from ${parent.author.login} ${parentTimeString?datetime?string.medium_short}</a></span>
    <#--</div>-->
    </#if> <#-- end parent check -->
    </#if> <#-- end message context check -->
  • Inactive User's avatar
    Inactive User

    After trying a bunch of freemarker sorcery, I just decided to take a straight line and query the parent for its datetime. 

    <#-- check to see if we have a message -->
    <#if env.context.message?? && env.context.message.uniqueId gt 0>

    <#assign root = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/root?restapi.response_style=view").message> <#-- get that message from rest -->

    <#assign parent = restadmin("/messages/id/${env.context.message.uniqueId?string.computer}/parent?restapi.response_style=view").message> <#-- get the parent message from rest -->


    <#if page.context.thread?? && page.context.thread.topicMessage??>
    <#assign apiVersion = "2.0"/>
    <#assign parentTimeQ = "SELECT post_time FROM messages WHERE id='${page.context.thread.topicMessage.uniqueId?string.computer}'"/>
    <#assign parentTime = restadmin(apiVersion, "/search?q=" + parentTimeQ?url + "&restapi.response_style=view").data.items![] />
    <#assign parentTimeString = parentTime[0].post_time />
    <#else>
    <#assign parentTimeString = ''/>
    </#if>

    <#if parent.@null[0]?? && parent.@null=="true"> <#-- check to make sure a parent exists -->

    <#-- if no parent you can put some text here or nothing -->
    <#else>
    <#--<div class="reply-to-stamp">-->

    <span class = "reply-author">
    &nbsp;|&nbsp;&nbsp;Posted in reply to <a href = "${parent.@view_href}" title = "Message from ${parent.post_time.@view_date}">message from ${parent.author.login} ${parentTimeString?datetime?string.medium_short}</a></span>
    <#--</div>-->
    </#if> <#-- end parent check -->
    </#if> <#-- end message context check -->