Forums

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

Set assignee base on affected version [Script runner]

Moses Thomas
Community Champion
October 25, 2019

Dear All,

I would  need some help trying of add a postfuction in a workflow, i don't know where the problem is, script runner  in  JIRA 8.4.2

 doesn't work :/  no errors so  may be i am  missing something.


import com.atlassian.jira.project.version.Version;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
import java.util.Collection;
import java.util.ArrayList;

Collection<Version> affectsVersions = issue.getAffectedVersions();

if(issue.issueType.name =="Bug" && issue.projectObject.key == "OS")
{

affectsVersions.each {  AfVersion ->

if(AfVersion == 'v2.20.0') issue.setAssigneeId("jira_champ")

}

}

 

 

Thanks!

Moses

2 answers

1 accepted

0 votes
Answer accepted
Moses Thomas
Community Champion
October 25, 2019

@Leo  Every time i get user by name issue is  set  to  unassigned   in jira 8.4.2 so  i decided to set assignee by user ID, Kudos Leo thanks alot !! for your input  :)  my  perfect solution will be

import com.atlassian.jira.issue.Issue;

def aVersions = issue.getAffectedVersions()

for(v in aVersions){
if(v.getName() == "V2.20.0" || v.getName() == "v2.23.0" || v.getName() == "V2.20.0" && v.getName() == "v2.23.0"){
issue.setAssigneeId('suport-pro')
}
}

Best regards,

Mo

2 votes
Leo
Community Champion
October 25, 2019

Hi @Moses Thomas 

Below snippet may help you on setAssignee based on affectedVesion through workflow post-function

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

if (issue.issueType.name == "Bug" && issue.getAffectedVersions().getAt(0)?.getName() == "version-name-to-be-checked"){
       UserManager userManager = ComponentAccessor.getUserManager();
      def user = ComponentAccessor.getUserManager().getUserByName("Assignee Name")
      issue.setAssignee((user))
}

Note: this will just check for the first version, you may need to iterate over them if there are many

 

BR,

Leo

Moses Thomas
Community Champion
October 25, 2019

@Leo  Thanks for the quick reply, exactly i have many of  these versions as a collection (List) and  this is what i tried to  do  but not  getting right result..

 

BR,

Mo

Leo
Community Champion
October 25, 2019

Hey, you just want to check one particular version from the list and assign it to particular one if that version associated to the current issue?

Moses Thomas
Community Champion
October 25, 2019

@Leo  Yes, your code snippet checks only the first version in the list but i need assign it to the user once  i find it from  the list.

Leo
Community Champion
October 25, 2019

You can try this below snippet to iterate over your versions, I used this script for version copying, it may require minor changes in your case

def aVersions = issue.getAffectedVersions()

for(v in aVersions){
if(v.getName() == "version-name-to-be-checked"){
UserManager userManager = ComponentAccessor.getUserManager();
def user = ComponentAccessor.getUserManager().getUserByName("Assignee Name")
issue.setAssignee((user))
}
}
Like Moses Thomas likes this

Suggest an answer

Log in or Sign up to answer