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

Confluence- get page id from 'LabelAddEvent' - event listeners

I use 'Label Add Event', and I need to get the page id.

How can I do it in 'event listeners'?

 

I have Confluence version 6.13.8

 

Tnx,

Daniel

1 answer

1 accepted

Hi Daniel! 

You can get the Id of the page the label is being added to by first getting the Labellable object from the Label event and then casting it as a Page. The page Id can then be retrieved from with the getContentId() method. 

I've added a code snippet below that shows this in action!

import com.atlassian.confluence.pages.Page

def page = event.getLabelled() as Page

log.warn page.getContentId()

I hope this helps!  

Thanks, 
Lee

Hi, Thank you @Lee Wonnacott _Adaptavist_ 

I got this error:

confluence.png

Hi Daniel, 

As you're listening for multiple events you will need to cast the provided event to the particular event you wish to take action on. 

So, in this case, you will need to do the following:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.event.events.label.LabelAddEvent

def labelEvent = event as LabelAddEvent

def page = labelEvent.getLabelled() as Page

log.warn page.getContentId()

I'd also recommend separating the events you are listening for into individual listeners as this will make them simpler to implement and maintain your code. 

Thanks, 
Lee

Thank you, It worked and I caugth the event and the page id!

Bug now I am handeling with a different problem with this script:

https://community.atlassian.com/t5/Confluence-questions/Update-title-of-page-using-event-listeners/qaq-p/1357183#M174207

 

Can you help me with it please?

 

Daniel

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

175 views 2 9
Read article

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