I have a Custom Field that is a select list. When an issue is created, I would like the issue to be assigned to a particular user in a script runner post-function based on the value of that custom field selected on the Create Screen. I have tried a million different things, and nothing seems to work - the issue always gets assigned to the Project Lead. Can anyone point out what I'm doing wrong?
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def taskTypeField = customFieldManager.getCustomFieldObjectByName("Task Type")
def taskType = issue.getCustomFieldValue(taskTypeField).toString()
def project = issue.getProjectObject()
def lead = project.getProjectLead()
def reporter = issue.getReporter()
if(taskType == "Self-Directed")
{
issue.setAssignee(reporter)
}
else
{
issue.setAssignee(lead)
}
getCustomFieldValue returns an instance of Option for select lists. Try:
def taskType = issue.getCustomFieldValue(taskTypeField)?.value
Also, you can enable logging in order to debug your scripts - logging the value of taskType would help in this case.
I did try that - one of the many things I tried to no avail. BUT! I didn't have the logging on to debug my scripts, so I am definitely going to try that out and see if I can figure out what's going on there...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK - this is getting even more bizarre... So, I put in the logging support as you suggested - thank you btw - SUPER helpful and I searched everywhere how to do that and finally you pointed me to a simple implementation - thank you!
So, I'm definitely getting the correct value of the select list - I'm getting the project lead and reporter - and I'm even going into the correct branch of the if statement based on the select list value!
So, what seems to be happening is that the setAssignee step is not working - BAH! How do I fix that??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to call issue.store() after setting the assignee. This, however, is not recommended anymore - the "proper" way to do it is via using IssueService.validateUpdate() and update() methods.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Interesting... That's odd, because I have a different script that does the exact same thing - simply issue.setAssignee and it appears to work... I'll try it though and see...
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This worked for me:
//
// Script which sets the assignee in a Service-Now Jira workflow from a single-pick Approver
// custom field: "User Picker (single user)"
//
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
// get our custom field Approver, error checking needed here
CustomField field = customFieldManager.getCustomFieldObjectsByName("Approver").iterator().next()
ApplicationUser user = (ApplicationUser)issue.getCustomFieldValue(field);
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// set the assignee and update the issue as the logged-in-user
issue.setAssignee(user)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK - this is getting even more bizarre... So, I put in the logging support as you suggested - thank you btw - SUPER helpful and I searched everywhere how to do that and finally you pointed me to a simple implementation - thank you!
So, I'm definitely getting the correct value of the select list - I'm getting the project lead and reporter - and I'm even going into the correct branch of the if statement based on the select list value!
So, what seems to be happening is that the setAssignee step is not working - BAH! How do I fix that??
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.