ScriptRunner Groovy Script based on issue type

Daniel Mendes April 12, 2017

Good morning!

I am new with groovy / scriptrunner and I am having difficulties in writing a script. The request is to use a post-function in the Create transition workflow to re-route tickets to a specific user when issue type = ‘Incident’ and Component is not set.

My idea is to use the inline postfunction option to achieve this. Can anyone help with the script to do this? Thanks.

2 answers

4 votes
JohnsonHoward
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 13, 2017

Hi Daniel,

To do this using a post-function you wil need to add this code:

 

 

import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor


UserManager userManager = ComponentAccessor.getUserManager();
MutableIssue issue = issue
if(issue.issueType.name == "Incident" && issue.getComponents().size() == 0 ){

issue.setAssignee(userManager.getUserByName("Test"))


}


 

Replace the 'Test' user with whomever you would like to set the issue to. The post-function will need to appear first in the list for this to work. 

You could also do this as a behaviour on the 'Assignee' field and change it depending on the form field value of componant and issue type. 

Let me know if this is what you were looing for, or if I have misundertood and you need some other solution.

Regards,

Johnson Howard

Daniel Mendes April 13, 2017

Thanks for your prompt response Johnson. I am still to test this as our associates have a new type of request now.

 

As soon as I have this tested, I will update this thread. Thanks.

JohnsonHoward
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 20, 2017

Any update on this Daniel?

Daniel Mendes April 26, 2017

Good morning Johnson,

 

Sorry for the late reply. Just able to test it now in our non-prod instance.

I am attaching three screen shots with the error messages. Hope you can get them.

Any suggestions? Thanks.

 

1.png2.png3.png

JohnsonHoward
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 27, 2017

What version of JIRA and ScriptRunner are you using?

Daniel Mendes April 27, 2017

JIRA is 6.4.12

ScriptRunner is 4.1.3.24

 

Thanks.

JohnsonHoward
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 27, 2017

Try with just:

issue.assignee = userManager.getUserByName()

Daniel Mendes April 27, 2017

I still get errors. Attached. Thanks.

 2.2.png2.1.png2.png1.png1.1.png

JohnsonHoward
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 28, 2017

If you update your JIRA and Scriptrunner, the previous code will work.

NT March 20, 2018

I have a similar case,  I want to copy custom field value of one issue type to all other issues of the project.

 

We have Issue type "Project info"  and we created one issue of "Project info" type per project to maintain all project related information.

So anything changes in the project we update the respective field on of  project info issuetype of that project.

Now I want to copy one of the custom field value of project info issue type to all other issue of that  project.

 

Can anybody help me with this?

 

Thanks in advance.

0 votes
Sayan Kaiser March 16, 2020

Thanks JohnsonHoward this is working brilliant for me 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events