Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scroll Version page key in user macro

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2020

Hi all

We have Scroll Version for Confluence. With this we are able to create multiple versions of one page. 

We also can add a "Page Key". A page key can be added manually. 
image.png

Now I wanted to create a list of all pages in this space and their page key, if they have one.

But I don't see anything where this information is stored... 

How can I get access to this information? I want to create an user macro.
I'm using also ScriptRunner, so also a ScriptRunner solution is highly appreciated.

Regards, Dominic 

1 answer

1 accepted

1 vote
Answer accepted
Matt Reiner _K15t_
Atlassian Partner
July 29, 2020

Hi @Dominic Lagger

Here is a custom user macro definition that might be helpful for you. Placing it on any page will render a table with all pages with keys, their keys, and the versions for the current space. You can restrict the page to not interfere with the rest of your documentation. To re-create it in your instance, select the following settings:

Screen Shot 2020-07-22 at 14.51.53.png

In the Template part, enter the following definition:

## @noparams
<table class="confluenceTable tablesorter tablesorter-default" >
    <thead class="tableFloatingHeaderOriginal">
        <tr role="row">
            <th class="confluenceTh">Page name</th>
            <th class="confluenceTh">Page key</th>
            <th class="confluenceTh">Version</th>
        </tr>
    </thead>
    <tbody id="pk-table-output"></tbody>
</table>
<script>
    let baseUrl = Confluence.getBaseUrl().concat(Confluence.getContextPath());
    let spaceKey = AJS.Meta.get("space-key");
    console.log(baseUrl);
    function pkArray(pkPages) {
        var pkTable = "";
        var i=0;
        while (i < pkPages.length) {
            var page = pkPages[i];
            if (page.scrollPageKey != undefined) {
                pkTable = pkTable.concat("<tr role='row' ><td class='confluenceTd'><a href='"+baseUrl+"/pages/viewpage.action?pageId="+page.confluencePageId+"'>"+page.scrollPageTitle+"</a></td><td class='confluenceTd'><a href='"+baseUrl+"/display/_PK/"+spaceKey+"/"+page.scrollPageKey+"'>"+page.scrollPageKey+"</a></td><td class='confluenceTd'>"+page.targetVersion.name+"</td></tr>");
            }
            i++;
        }
        return pkTable;
    }

    let pkRequest = new XMLHttpRequest();
    pkRequest.open("POST", ""+baseUrl+"/rest/scroll-versions/1.0/page/"+spaceKey);
    pkRequest.setRequestHeader("Content-Type", "application/json");
    pkRequest.send(JSON.stringify([{"queryArg": "scrollPageKey", "value": "*"}]));
    pkRequest.onload = () => {
        if(pkRequest.status === 200) {
            document.getElementById("pk-table-output").innerHTML = pkArray(JSON.parse(pkRequest.response));
        }
        else {
            console.log("whoopsie")
        }
    }
</script>

If this doesn't work for you, feel free to reach out to use: support@k15t.com.

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2020

Hi @Matt Reiner _K15t_ 

This works great, thanks!

Is there any possibility to get a list from all the pages, which doesn't have any page key? 

Regards, Dominic

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2020

I found a possible solution, but I'm not sure if it's correct: 

Change the queryArg:

pkRequest.send(JSON.stringify([{"queryArg": "scrollPageKey", "value": "*"}]));

And change the if statement:

if (page.scrollPageKey != undefined) {
pkTable = pkTable.concat("HTML HERE");
}else{
pkTable = pkTable.concat("HTML HERE");
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events