I am having an issue where I am trying to set an assignee based on a custom field value. This current code block below shows no errors when editing and I also get no errors when running in a workflow post function. However, the assignee of the field does not change. What am I doing wrong?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager();
def userManager = ComponentAccessor.getUserManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cField = customFieldManager.getCustomFieldObject("customfield_12400");
def cFieldValue = issue.getCustomFieldValue(cField);
if (cFieldValue == "Security") {
def assignee = userManager.getUserByKey("i849194");
issue.setAssignee(assignee);
}
else if (cFieldValue == "Operations") {
def assignee = userManager.getUserByKey("i826121");
issue.setAssignee(assignee);
}
else if (cFieldValue == "Instance Creations/Backups") {
def assignee = userManager.getUserByKey("i825046");
issue.setAssignee(assignee);
}
Hello,
Try to write it like this:
if (cFieldValue.toString() == "Security") {
def assignee = userManager.getUserByKey("i849194");
issue.setAssignee(assignee);
}
else if (cFieldValue.toString() == "Operations") {
def assignee = userManager.getUserByKey("i826121");
issue.setAssignee(assignee);
}
else if (cFieldValue.toString() == "Instance Creations/Backups") {
def assignee = userManager.getUserByKey("i825046");
issue.setAssignee(assignee);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jimit,
Where is this post function? In create transition or another? Also, in which order is it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is the first transition after create. So the second transition. Currently this post function is at the top of the list in terms of order to follow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm having a similar issue. I was going to open my own question, but I think the answer you get will be the same as the answer I need, so maybe I can contribute a bit.
I think the problem has to do with needing to persist the data. Here's the code I'm trying to get to work:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
log.setLevel(org.apache.log4j.Level.DEBUG)
def reviewCompletionStatusField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10209")
def epicLinkField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10100")
def issueType = event.issue.issueType.name
//Initial/Validation Review:
//if Not Approved, assign triage subtask to coordinator and put it into todo
//if Approved with comments or approved, assign Canada Initial Review subtask to canada contact (tbd) and put it into todo, also notify coordinator
//Approved, Approved With Comments, Not Approved
log.info event.toString()
//Only do work if the task that changed was DND Initial Review or DND Validation Review
if(issueType == "ADS Initial Review" || issueType == "ADS Validation Review"){
log.info "Triggered by change made to issue ${event.issue}"
if (event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Review Completion Status"}) {
def newValue = event.issue.getCustomFieldValue(reviewCompletionStatusField)
log.info "The Review Completion Status field has changed to ${newValue}"
MutableIssue remedIssue = null
Issue parent = event.issue.getParentObject()
def subtaskToAssignName = "";
switch(newValue){
case "Not Approved":
subtaskToAssignName = "Triage"
break;
case "Approved":
case "Approved With comments":
subtaskToAssignName = "Initial Review"
break;
}
parent.getSubTaskObjects().each{sibling->
if(sibling.getIssueType().name == subtaskToAssignName){
remedIssue = sibling as MutableIssue
log.info "Remediation issue found: ${remedIssue.key} - ${remedIssue.summary}"
}
}
if(remedIssue != null){
// Issue epic = parent.getCustomFieldValue(epicLinkField) as Issue
ApplicationUser coordinator = ComponentAccessor.getUserManager().getUserByName("someUserName")
log.info "The coordinator lead for this task is ${coordinator}"
remedIssue.setAssignee(coordinator)
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (!loggedInUser) {
loggedInUser = UserManager.getUserByName('jira_bot')
}
def validateAssignResult = ComponentAccessor.getIssueService().validateAssign(loggedInUser, issue.id, coordinator.getKey())
ComponentAccessor.getIssueService().assign(loggedInUser, validateAssignResult)
}
}
}
I think the line that's giving me some trouble is towards the end:
def validateAssignResult = ComponentAccessor.getIssueService().validateAssign(loggedInUser, issue.id, coordinator.getKey())
I think I need to find a way to get the user id in string format to replace 'coordinator.getKey()'
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.