PAULEM
6 years agoAdvisor
Cannot get last_post_time
I want to put a banner at the top of a thread if the last_post_time is older than three months. Here's my code (just using a static message ID while testing):
<#assign cutoff = (.now?long - 90 * 86400000)?number_to_date /> <#assign msgQuery = "SELECT conversation.last_post_time FROM messages WHERE id='170' AND depth=0" /> <#assign msgInfo = rest("2.0", "/search?q=" + msgQuery?url) /> <#assign postDate = msgInfo.data.items.conversation.last_post_time?long /> <#list msgInfo.data.items as message> <#if postDate?number_to_date <= cutoff> <div id="post-closed"> <p>This conversation is old. If you have a question please start a new post.</p> </div> </#if> </#list>
No matter what I've tried, I can't seem to get the last_post_time value. In the code above, it falls over at the <#assign postDate...> line. It tells me:
The following has evaluated to null or missing
But testing the query in the API browser tells me the value is there! I'm pretty sure I'm missing something rea-a-ally obvious but I've tried everything I can think of.
Can anyone help me out please?
Thanks in advance.
Paul
Query will return a single message but still it will be an array. So either you need to iterate it in list or do it like this
<#assign postDate = msgInfo.data.items[0].conversation.last_post_time?long />