It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

## 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>

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

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.

0 votes

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!

Thanks to all in finding the solution.

 

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

353 views 11 11
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you