Forums

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

Assign issue to a specific user based on the text in the summary field

Aravindi Amarasinghe
Contributor
March 20, 2018

Hi All, 

I have a requirement to assign issue to a user based on a specific text in the summary field. 

I come up with this script but it doesn't do the job. Can somebody help me to find the error in this script? 

import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;

MutableIssue myIssue = issue;
String summary = issue.getSummary();

String[] result = myIssue.summary.toString();


if (result!=null && result.length>3)
{

//Capture the word in summary

if (myIssue.summary.toString().matches("#RACF#"))
{

//Assign issue to the user

def user = userManager.getUserObject("au.aaa@bbb.com");
if (user) myIssue.setAssignee(user);
}
}

 

3 answers

1 accepted

0 votes
Answer accepted
Aravindi Amarasinghe
Contributor
March 25, 2018

Hi @Alexey Matveev @Jenna Davis 

Thanks. I have modified the script with regex and it works fine. 



import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;


MutableIssue myIssue = issue;
String summary = issue.getSummary();
def userManager = ComponentAccessor.userManager;

log.error("Summary choosen: " + summary)

//Defining custom fields
String userName;



if (myIssue.summary.toString().matches("#RACF#.*")){
userName = "au.aaaa@bbb.com"

}

log.error("Username chosen: " + userName)

//Assigning the issue to the value picked by userName

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(ComponentAccessor.getUserManager().getUser(userName))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

0 votes
Jenna Davis
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.
March 21, 2018

Hello, 

Like Alexey said, if you could give a bit more context into what errors you're seeing and what isn't working that would be helpful. 

I did notice that you're trying to use the User Manager class without importing it anywhere. You need to add this line near the top of your code in order to define your userManager variable and access the User Manager class. 

def userManager = ComponentAccessor.userManager

Please let me know if this helps, or if you have any other questions. :)

Jenna

0 votes
Alexey Matveev
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.
March 21, 2018

What is the error? Where do set the script? In a post function? On issue create? What is the order of the script in the list of post functions?

Suggest an answer

Log in or Sign up to answer