ScriptRunner Groovy Script based on issue type

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.

1 answer

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

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.

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

What version of JIRA and ScriptRunner are you using?

JIRA is 6.4.12

ScriptRunner is 4.1.3.24

 

Thanks.

Try with just:

issue.assignee = userManager.getUserByName()

I still get errors. Attached. Thanks.

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

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

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

358 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you