Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Want to update the exiting component name, description, lead using a script post function.

Mani Reddy April 11, 2018

Team,

With the custom script I am able to add new components ( Component name, Lead, Description ) every time I create a new issue based on the summary, description, assignee.

However I want to be able to update the existing Component Information by creating a look back transition and applied the below script, it did not change the existing component and created a new component instead.

 Any help would be appriciated

 

 



3 answers

0 votes
Salim Hammar
Contributor
February 19, 2022

Hi @Ivan Tovbin 

Thank you for your answer but i have a probleme 

can you help me please - > https://community.atlassian.com/t5/Jira-Software-questions/Updated-Components-between-Projects/qaq-p/1949873

 

Thanks in advance

0 votes
Salim Hammar
Contributor
February 15, 2022

Hi @Ivan Tovbin 

I succeedded do the function create and update a component between project but actually i find for do delete

 

You have idea ?

Thanks in advance

0 votes
Ivan Tovbin
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 14, 2018

Hi Mani,

Here's how you update a component list for a given issue:

def componentns = issue.getComponents()
components.add(newComponent)
projectComponentManager.updateIssueProjectComponents(issue, components)
Salim Hammar
Contributor
February 11, 2022

Hi @Ivan Tovbin 

I would like create a script listenner when i modify the name component he change in the other project 

I have this script but he don't work because i have projectComponenetManager.create so when i edit a component he go to create a new component instead of to edit in the other projet linked 

 

Look the script 

SCRIPT8COMPO.png

 

You have idea for implants the "project projectComponentManager.update" in the place of "projectComponenetManager.create" because actually when i edit a component he to create a new component with the names changed

Ivan Tovbin
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.
February 15, 2022

@Salim Hammar If I understand your requirement correctly, you have a listener that monitors component name changes in one project and updates components with the same name in other projects to keep them all in sync.

If the above is true then you have a logic problem in your code. Specifially here:

def componentTemp = projectComponentManager.findByComponentName(project.getId(), component.getName())

 Here, you are trying to find the components in other project with the same name. If none are found then create a new one, else uptade existing one. The problem is that right now you will NEVER find a component with the same name and thus will ALWAYS create a new one. This is because the listener triggers AFTER the name of the source component have been changed. And you are using a NEW component name to find a component in existing project. You need to somehow get the OLD name of the source component and use it instead to search for existing components in other project.

Salim Hammar
Contributor
February 15, 2022

Hi  @Ivan Tovbin 

I succeedded do the function create and update a component between project but actually i find for do delete

 

You have idea ?

Thanks in advance

Ivan Tovbin
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.
February 17, 2022
Salim Hammar
Contributor
February 18, 2022

Hi @Ivan Tovbin 

 

Thanks you for your answer , i would like knwo it's possible to blocked a add component in the project jira ?

Or a function when i create a component this he deleted automatically ?

 

Thanks in advance ?

Ivan Tovbin
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.
February 19, 2022

@Salim Hammar I don't think there is a way to block component creation. If a user has Project Administrator permission, he can create components. 

Sure, you can delete components right after they are created. For this you'll need a listener which would monitor the ProjectComponentCreatedEvent (https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/event/bc/project/component/ProjectComponentCreatedEvent.html).

But honestly if you need to delete something that wasn't supposed to be created in the first place, the best practice would be to review your whole business process, so that it doesn't involve creating any potentially unwanted entities.

Hope this helps.

Suggest an answer

Log in or Sign up to answer