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

This widget could not be displayed.

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.

Any update on this Daniel?

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

515 views 3 18
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