Skip to main content
Skip table of contents

Most recently viewed macro

Please make sure you have read through the Prerequisites / Basic Set-up.

You will need to fit the name of the datasource to your own Confluence installation.

Using this query you can find out which query was looked at last and also immediately go to the page it was viewed on.

It also provides you with an example of how you could use the $friendlyDateFormatter in your templates.

Query

SQL
SELECT QUERY_NAME, DATE, CONTENT_ENTITY_ID
FROM {YOUR_TABLE_NAME}
WHERE QUERY_NAME != 'PQMU-most-recently-viewed'
ORDER BY DATE desc
LIMIT 1;

Template

CODE
## Adjust the date format to your liking
#set($dateFormat = "yyyy-MM-dd HH:mm")
 
## @param emptymsg:The query returned no result! Make sure you enabled statistics in the global PocketQuery configuration.
 
#set($name = $result.get(0).QUERY_NAME)
#set($viewedDate = $result.get(0).DATE)
#set($friendlyDateMessage = $friendlyDateFormatter.getFormatMessage($viewedDate))
#set($contentId = $result.get(0).CONTENT_ENTITY_ID)
 
<style>
.pqmu-most-recently-viewed {
  background-color: #f9f9f9;
    padding: 20px;
    margin: 10px;
    width: fit-content;
}
 
.pqmu-most-recently-viewed h4 {
  border-bottom: 2px solid #ccc;
  padding: 0 50px 8px 10px;
  margin-bottom: 15px;
  margin-top: 0;
  font-size: 16px;
  font-weight: bold;
  line-height: 1.25;
  text-transform: none;
  margin: 20px 0 0 0;
}
</style>
 
<div class="pqmu-most-recently-viewed">
  <h4>Most recently viewed query</h4>
    <p>"$name" <em>($dateFormatter.formatGivenString($dateFormat, $date))</em></p>
    <p>The query was viewed $i18n.getText($friendlyDateMessage).</p>
    <p><a href="$!req.contextPath/pages/viewpage.action?pageId=$contentId">See the page it was viewed on.</a></p>
</div>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.