How can I read a page property from a parent page ?

Peter Florijn October 18, 2019

I have a master page and a child page.

In the master page I have a page property macro with several properties.

In the child page I want to copy a specific property.

I have found that there is an API call like this:

/rest/masterdetail/1.0/detailssummary/lines?cql=id=25807045&spaceKey=XXXX&headings=Conclusie&pageIndex=0"

When called in the browser I get the correct result, namely the value of the property "Conclusie".

I'm struggling to use this in a user macro.

This is what I have sofar:

## @noparams

<script type="text/javascript">
AJS.$.ajax({
url: "/rest/masterdetail/1.0/detailssummary/lines?cql=id=25807045&spaceKey=XXXX&headings=Conclusie&pageIndex=0",
contentType: 'application/json',
type: "GET",
success: function(msg){
alert(msg);
}
</script>

I get a rendering error.

Error occurred rendering template content

Would appreciate any hints or suggestions.

TIA

3 answers

1 accepted

0 votes
Answer accepted
Peter Florijn October 31, 2019
## Remarks: properties with space in the name cause problems
## https://stackoverflow.com/questions/6802765/jquery-dealing-with-a-space-in-the-id-attribute
## not allowing page properties with spaces in it solves it at the source, but you want labels with spaces
## $prop.replace(" ", "")) solved it

## @Param PropertyName:title=Property|type=string|desc=Name of the page property of the parent page|Required=true

#set ($parentID = $content.getParent().getIdAsString())

#set ($prop = "$paramPropertyName")

#set ($propid = $prop.replace(" ", ""))

<div id="$propid"></div>

<script type="text/javascript">

jQuery.ajax({

url: "/rest/masterdetail/1.0/detailssummary/lines?cql=id=$parentID&spaceKey=ISMS&headings=$prop&pageIndex=0",

contentType: 'application/json',
dataType: 'json',

type: "GET",

success: function(data){

var props = data;

property = props.detailLines[0].details[0];

$("div[id=$propid]").html(property);

},
});

</script>
0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 21, 2019

Hello there @Peter Florijn !

I can assist you a little with the issue that you are currently facing. The rendering issue you are seeing is probably due to this line here:

AJS.$.ajax({

Try swapping it with this:

jQuery.ajax({

Also, it seems that we are missing a few brackets. Here is what it would look like with those placed and jQuery.ajax replacing AJS.$ajax:

## @noparams

<script type="text/javascript">

jQuery.ajax({

url: "/rest/masterdetail/1.0/detailssummary/lines?cql=id=327708&spaceKey=DEM&headings=00&pageIndex=0",

contentType: 'application/json',

type: "GET",

success: function(msg){

alert(msg);

},

});

</script>

For further assistance on how to use JavaScript within Confluence, you can refer to our documentation:

Or even reach out to our Developer Community, here:

Let us hear from you, Peter!

Peter Florijn October 31, 2019

Thanks to all in finding the solution.

 

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 31, 2019

Hey Peter! Thanks for coming back to the thread. Glad to read that my reply helped you find the solution.

Come share with the community (or the Developer Community!) some time.

0 votes
Nicolai Sibler
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.
October 21, 2019

Hi Peter,

I don't have the skills to analyse your User Macro, but I'd simply put an Excerpt Macro in the table cell of the desired page property on the parent page and display it on the child page with the Excerpt Include Macro - of course, this won't work when you use the Excerpt Macro for another purpose...

 

Best regards,

Nicolai

Peter Florijn October 21, 2019

Hello @Nicolai Sibler 

Thanks for your reply. I also considered Excerpt macro, but this is not feasibile because I have a lot of different Master (source) pages.

So I need a more dynamic approach.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events