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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,881
Community Members
 
Community Events
184
Community Groups

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

0 votes
Answer accepted
Lee Wonnacott
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.
Apr 20, 2020

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 

I got this error:

confluence.png

Lee Wonnacott
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.
Apr 20, 2020 • edited

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
AUG Leaders

Atlassian Community Events