Forum Discussion

xorrkaz's avatar
xorrkaz
Genius
14 years ago

How to get the thread ID when viewing a thread?

I would like to extract the thread ID of the current thread from the thread page.  However, when I use the env.context.message.uniqueId variable, I get the last message ID of the thread.  I want the first (i.e. the initial question).  How can I get that without making multiple REST calls?

 

For example, if the page URL reads:

 

/board/Default-email-notification-to-original-person-starting-a/td-p/66

 

But the last message on the page has ID 69, then my REST call returns 69 instead of 66.  I want to get the 66.  Thanks!

  • oopsies - try this .${page.context.thread.topicMessage.uniqueId}

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)

    You should be able to get the root message id with one REST call using that env.context.message.uniqueId variable.  It will look something like this:

     

    /restapi/vc/messages/id/${env.context.message.uniqueId }/root

    This will return the topic message of the entire thread.  From that you can get the id.

     

    You can also look at using the ${page.context.thread} variable.  That should get you the entire thread (along with it's id) without doing a rest call.  Just be careful where that call is made, it is only available on pages with threads like the ForumTopicPage.  You probably want to test for null before trying to use it.

    • xorrkaz's avatar
      xorrkaz
      Genius

      Thanks, Kaela!  When I tried ${page.context.thread} I was getting back some Java .toString() type notation.  I had to search around a bit to find the env stuff.  Thanks for the REST URL.  I was hoping for a Freemarker variable, but REST will certainly work.

      • xorrkaz's avatar
        xorrkaz
        Genius

        FYI, here is what I see when I use ${page.context.thread}:

         

        lithium.eval.velocity.ThreadTemplateModel@e25235

         

        I imagine this is an Object.  How can I access members of this object?