Forums

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

Set component depending to text in summary

wajih zouaoui
Contributor
June 11, 2019

Hi,

 

we are using listners in jira to create auto issues and we want to use scriptrunner post-function scripts in order to set a component depending to the summary. e.g:

if summary text ~ A then component = 1

if summary text ~ B then component = 2

...

 

Can  you please help us , we are trying to use script runner with custom scripts and we are not used to yet. So your help will be really appreciated.

 

Thanks in advance.

 

Best regards,

Wajih

2 answers

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
June 11, 2019

Hi @wajih zouaoui ,

Please try this script : 

import com.atlassian.jira.component.ComponentAccessor

if (issue.getSummary().contains("A")){
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectObject().getId(),"1")
issue.setComponent([component])
}
else if (issue.getSummary().contains("B")){
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectObject().getId(),"2")
issue.setComponent([component])
}

Note that this will overwrite current components.

Antoine

Antoine Berry
Community Champion
June 12, 2019

Hi @wajih zouaoui ,

What do the logs return ? Are you sure you replaced the component with the correct name ?

Antoine

wajih zouaoui
Contributor
June 12, 2019

Hi @Antoine Berry ,

 

here is the log return .

 

2019-06-12 16:45:20,311 https-jsse-nio-443-exec-6 WARN wzouaoui 1005x617x1 lrnfk2 172.22.12.152 /browse/CRMGR-4689 [c.atlassian.ozymandias.SafePluginPointAccess] Unable to run plugin code because of 'java.lang.NullPointerException - null'.
2019-06-12 16:45:21,381 https-jsse-nio-443-exec-18 WARN wzouaoui 1005x626x1 lrnfk2 172.22.12.152 /rest/projects/1.0/project/CRMGR/lastVisited [c.atlassian.ozymandias.SafePluginPointAccess] Unable to run plugin code because of 'java.lang.NullPointerException - null'.

 

We are using the 7.13.1 Jira softwae server release.

The plugin is running and tested in this project with built-in scripts ( e.g : auto add to active sprints ) and it works perfectly.

 

Here your code customized with our local datas 

Antoine Berry
Community Champion
June 12, 2019

duplicate

Antoine Berry
Community Champion
June 12, 2019

If you use this code what does get logged ? 

import com.atlassian.jira.component.ComponentAccessor

if (issue.getSummary().contains("A")){
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectObject().getId(),"1")
log.error("component : " + component)
issue.setComponent([component])
}
else if (issue.getSummary().contains("B")){
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectObject().getId(),"2")
log.error("component : " + component)
issue.setComponent([component])
}
wajih zouaoui
Contributor
June 13, 2019

Thanks a lot Antoine , i found the error and it was my bad.

The post-function script has been placed after "Creates the issue originally." ( like i've done with the auto add to active sprint built-in script ).

 

Now it works like a charm.

 

Many thanks again for your effort.

 

Kind Regards,

Wajih

Like Antoine Berry likes this
1 vote
wajih zouaoui
Contributor
June 12, 2019

Hi Antoine,

 

thanks a lot for the reply but sorry it didn't work :( 

Suggest an answer

Log in or Sign up to answer