A custom single picker custom field is being set as part of the transition to Create Subtask, but cannot get the Assignee to populate with the user's account - it populates instead with a string in the format of "username(username)".
I have tried numerous examples of the "set assignee" I found online, but no success.
I can hardcode the Assignee, but cannot get the variable aspect that is needed. here is the last thing I tried:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def field1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Responsible Business Mgr"}
def implUser = sourceIssue.getCustomFieldValue(field1)
def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.assigneeId = implUser
issue.setReporter(currentAppUser);
The custom single-picker field, Responsible Business Mgr, the name "tcarwell" is entered, and what appears as the Assignee on the subtask is "tcarwell(tcarwell)"
All feedback welcomed,
Wayne
Hi Wayne,
Are you putting this as a post-function? Where you are putting it in the order of post-functions can have an effect. Also so can if you are trying to update an issue outside of the one being transitioned.
If it is at the bottom or if you are trying to update a different issue to the one being transitioned, then you will need to update the database yourself in the code for the change to have an effect. In the example below I have shown how to do this.
If it is on the Create transition and at the top of the order of post-function, then you will need to be aware that the 'issue' has not yet technically been created, therefore the variable 'issue' will not yet be assigned.
The example below was one I ran in the console, hence why line 13 where I have had to get the issue manually. This example also shows you how to get the custom field value of a user picker and turn it into a Application user so you can then use it to set the assignee.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager im = ComponentAccessor.getIssueManager()
Issue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-5")
def field1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "User Picker"}
def user = issue.getCustomFieldValue(field1) as ApplicationUser
def userManager = ComponentAccessor.getUserManager()
issue.setAssignee(user)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
im.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hope this helps,
Johnson Howard (Adaptavist)
Johnson - thank you for your response, and while the above did not operate as expected, I as able to take the above as input and found the following to work as needed:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager im = ComponentAccessor.getIssueManager()
def field1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Responsible Business Mgr"}
def user = issue.getCustomFieldValue(field1) as ApplicationUser
def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(user)
issue.setReporter(currentAppUser);
To help fill in the rest of the story -we are using V7.4.4 of JIRA and v5.3.5 for ScriptRunner. This is a Script Post-Function on a workflow transition of an existing Parent Issue. I am using the "Create a sub-task" for the script.
The custom single-picker field "Responsible Business Mgr" is on the transition screen of the Parent Issue, for the workflow action that creates the Subtask. The above script now does the following:
As far as where in the order of Post Functions, I have it working as
Subtask will be created with issue type: EOL Bus Mgr and summary Bus Mgr Subtask -.
It is also worked in the 5th location
Subtask will be created with issue type: EOL Bus Mgr and summary Bus Mgr Subtask -.
I am sure there are some best practices I am over looking, and I did place this script just before the re-index.
Thanks again for your assistance in resolving this,
Wayne
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.