Forum Discussion

dustin's avatar
dustin
Expert
9 years ago

How do I get message id from Post Page?

On the Post Page, I would like to display a message based on the topic's age.

 

To do this, I first need to retrieve the ID of the topic message that is being replied to. The following didn't yield any results...

 

<#if page.context.thread??>
  <div>topicMessage: ${page.context.thread.topicMessage.uniqueId}</div>
</#if> 
<#if page.context.message??>
  <div>message: ${page.context.message.uniqueId}</div>
</#if> 

How should I be retrieving the topic message ID from the Post Page?

  • Because the message context object is not available on the post page, I found that you need to resort to other methods.

     

    The solution I implmented was to parse the request url with freemarker to grab both the board ID and message ID.  

     

    Here is the freemarker code...

      <#assign boardKey = "board-id">
      <#assign messageKey = "message-id">
    
      <#assign urlString = http.request.url>
      <#assign strCount = 0>
      <#list urlString?split("/") as subStr>
        <#if messagePos?? && strCount == messagePos>
          <#assign messageID = subStr>
        </#if>
        <#if boardPos?? && strCount == boardPos>
          <#assign boardID = subStr>
        </#if>
    
        <#assign strCount = strCount + 1>
    
        <#if subStr == boardKey>
          <#assign boardPos = strCount>
        </#if>
        <#if subStr == messageKey>
          <#assign messagePos = strCount>
        </#if>
    
      </#list>
    
      <#if boardID??>
          <div>Board ID: ${boardID}</div>
      </#if>
      <#if messageID??>
          <div>Message ID: ${messageID}</div>
      </#if>
  • Hi dustin,

     

    Did you try below context variable to bring the UniqueId:-

    ${env.context.message.uniqueId}

     

    Regards,

    Vishwajit Shinde. 

  • Hi dustin,

     

    I have tried most of the context variables for getting message id on replay page but no one is giving message id.

    As a work around you can retrieve the message id from URL manipulation [not good practice].

     

    Please replay if you get any better solution for this.

     

    Regards,

    Mahesh Revanwar

    If my post is helpful and answers your question, please give "Kudos" and "Accept it as a Solution."

    • vishwajit_shind's avatar
      vishwajit_shind
      Expert

      Hi mahesh_revanwar,

       

      What I can see is the Id that we have from the url is board  specific, It is not the actual Id of the message to which we are replying.

       

      So I don't thing this would be right approach to fetch the Id from the url. We may use local storage or session storage to carry the message Id at reply page.

       

      Regards,

      Vishwajit Shinde.

      • mahesh_revanwar's avatar
        mahesh_revanwar
        Expert

        Hi vishwajit_shind,

         

        If we get the board specific message id using that id we can get unique id of the message.

         

        Try this call

        <baseURLofCommunity>/restapi/vc/boards/id/<board-id>/messages/id/<message-id>

         Regards,

        Mahesh Revanwar

        If my post is helpful and answers your question, please give "Kudos" and "Accept it as a Solution."

  • Because the message context object is not available on the post page, I found that you need to resort to other methods.

     

    The solution I implmented was to parse the request url with freemarker to grab both the board ID and message ID.  

     

    Here is the freemarker code...

      <#assign boardKey = "board-id">
      <#assign messageKey = "message-id">
    
      <#assign urlString = http.request.url>
      <#assign strCount = 0>
      <#list urlString?split("/") as subStr>
        <#if messagePos?? && strCount == messagePos>
          <#assign messageID = subStr>
        </#if>
        <#if boardPos?? && strCount == boardPos>
          <#assign boardID = subStr>
        </#if>
    
        <#assign strCount = strCount + 1>
    
        <#if subStr == boardKey>
          <#assign boardPos = strCount>
        </#if>
        <#if subStr == messageKey>
          <#assign messagePos = strCount>
        </#if>
    
      </#list>
    
      <#if boardID??>
          <div>Board ID: ${boardID}</div>
      </#if>
      <#if messageID??>
          <div>Message ID: ${messageID}</div>
      </#if>
    • PerBonomi's avatar
      PerBonomi
      Boss

      Amazed this object still isn't available on such an important page.

       

      Either way, I found this, albeit ugly, to be the least required code to get the unique id

       

      <#assign u = http.request.url/>
      <#assign msg_non_unique_id = u?substring(u?last_index_of("/") + 1, u?length)/>
      <#assign msg_unique_id = rest("/boards/id/${coreNode.id}/messages/id/${msg_non_unique_id}/id").value/>