Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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
Diego Atlassian Team Oct 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!

Thanks to all in finding the solution.

 

Diego Atlassian Team Oct 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.

Suggest an answer

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

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

480 views 24 9
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