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
@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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.