Forum Discussion

xorrkaz's avatar
xorrkaz
Genius
14 years ago
Solved

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}

7 Replies

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    14 years ago

    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
    14 years ago

    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
    14 years ago

    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?

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    14 years ago

    Yeah, it's returning you a thread object.  I will go check if the knowledge base has doc for the thread object, but in the meantime here it is:

     

    thread

    NOTE: YOU CAN NOT CALL THIS DIRECTLY – calls like page.context.thread will return you a thread

    MethodDecriptionExampleVersion / Branch
    thread.board get the board for this thread
    ${page.context.thread.board}
    9.10
    thread.topicMessage get the topic message for this thread
    ${page.context.thread.topicMessage}
    9.1.0
    thread.discussionStyle get the discussion style for this thread
    ${page.context.thread.discussionStyle}
    9.10
    thread.webUi.url get the url to the web page for this thread
    ${page.context.thread.webUi.url}
    9.1.0

     

    If all you want is the thread id, I think this would work

    ${page.context.thread.topicMessage.id}

  • xorrkaz's avatar
    xorrkaz
    Genius
    14 years ago

    Thanks again, Kaela.  That sounded promising, but I'm getting weird results.  My topic URL looks like:

     

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

     

    When I do an alert("${page.context.thread.topicMessage.id}"), I get a pop-up that says "3" (I expected 66).  If I do a get on thread ID 3, I get something completely unrelated to this topic.  Am I interpreting the value of this property incorrectly or is there a different property to grab?

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    14 years ago

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