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
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
Hi @wajih zouaoui ,
What do the logs return ? Are you sure you replaced the component with the correct name ?
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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])
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antoine,
thanks a lot for the reply but sorry it didn't work :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.