Jira Custom Listener with event ProjectComponent*

PIERSON Cédric April 2, 2019

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
Joanna Choules
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.
April 4, 2019

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

0 votes
Salim Hammar February 15, 2022

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 

PIERSON Cédric March 2, 2022

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

Atlassian Community Events