How can I read a page property from a parent page ?
Asked by Peter Florijn:

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


Answers:
author: Peter Florijn
body: ```
## 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>
```


author: Diego
body: Hello there [@Peter Florijn](/t5/user/viewprofilepage/user-id/941481) !

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:
> * **++[How to use JavaScript in Confluence](https://confluence.atlassian.com/confkb/how-to-use-javascript-in-confluence-313458839.html)++**

Or even reach out to our Developer Community, here:
> * ++**[Atlassian Developer Community](https://community.developer.atlassian.com/)**++

Let us hear from you, Peter!

comments: author: Peter Florijn
body: Thanks to all in finding the solution.


author: Diego
body: 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.


author: Nicolai Sibler
body: 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

comments: author: Peter Florijn
body: Hello [@Nicolai Sibler](/t5/user/viewprofilepage/user-id/2649119)

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.


Tags: atl-adm

confluence-server

rest-api

server

user-macro