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);
}
}
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)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.