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,456,703
Community Members
 
Community Events
176
Community Groups

Jira Custom Listener with event ProjectComponent*

Dear all,

I would like to create my own custom listener for one dedicated project ( I can select this one in the dropdownlist ), by including events ProjectComponentCreatedEvent, ProjectComponentDeletedEvent.

 

At this time, I don't know how to retrieve the list of dedicated projects which can trigger this event.

I know that I can retrieve event objects ( event instanceof ProjectComponentCreatedEvent )

 

Second things : If I Create a new component in another project that one's selected in the custom listener, the event will be triggered !!

 

In fact, i'm doing a synchronization between one parent project and other project from the same 'Project Catégory'.

Can you provide me such informations please?

 

here some code source:

 

import com.atlassian.jira.event.bc.project.component.ProjectComponentCreatedEvent
import com.atlassian.jira.event.bc.project.component.ProjectComponentDeletedEvent
import com.atlassian.jira.event.bc.project.component.ProjectComponentUpdatedEvent
import com.atlassian.jira.bc.project.component.ProjectComponentImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectCategory;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import com.atlassian.jira.bc.project.component.ProjectComponentManager;

 

//retrieve the id of the parent , in this case it is hardcoded, because I don't know how to retrieve it

Project projectInitiale = ComponentAccessor.getProjectManager().getProjectObjByKey("PARENT");
Set<String> setOfDeliveryProject = ComponentAccessor.getProjectManager().getAllProjectKeys(projectInitiale.id);
//retrieve the category  of projectInitiale
ProjectCategory projectCategory = projectInitiale.getProjectCategory();
ProjectComponentManager projectComponentManager = ComponentAccessor.getProjectComponentManager()
//retrieve the collection of project with the category given as param
Collection<Project> collectionProject = ComponentAccessor.getProjectManager().getProjectsFromProjectCategory( projectCategory) 


if(event instanceof ProjectComponentCreatedEvent){
    def event = event as ProjectComponentCreatedEvent

ProjectComponent newProjectComponent = event.getProjectComponent() as ProjectComponentImpl

 

}

if(event instanceof ProjectComponentDeletedEvent){

}

 

Thanks in advance,

 

Cédric

 

2 answers

1 accepted

0 votes
Answer accepted

Hi Cédric,

Project filtration only applies to certain types of events, primarily issue-related ones. ScriptRunner does not currently extract project information from component-related events for filtration purposes, so the value of the Project(s) field in the listener config will have no effect in this case.

To achieve the project-specific action you want, you will need to filter explicitly in the code by checking event.projectComponent.projectId, which will be the numeric ID of the relevant project. Then you can decide whether to continue with the script or return early.

Yours,

Joanna Choules, Adaptavist Product Support

Hi @PIERSON Cédric  and @Joanna Choules 

Actually i have 2 script listenner : one for create a componet between project and another for update a component 

But actually i'm dont find a function for delete a component , when i delete componet for the project A (with the project key) in the project B he delete him too

 

You have idea ???

Thanks in advance 

dear @Salim Hammar  , what did you put as Event ? 

if you remove the RemoveEvent, nothing will happen.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events