Can't update multiple user picker custom field.
Workflow transition's post function script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def Approvers = customFieldManager.getCustomFieldObjectByName("MultipleUserPicker")
List<applicationuser> newApprovers = [];
ApplicationUser user = userManager.getUserByKey("user1");
newApprovers.add(user);
user = userManager.getUserByKey("user2");
newApprovers.add(user);
issue.setCustomFieldValue(Approvers, newApprovers)
issue.store();
This code gives no mistake in text editor, but when I performing transition it alerts:
It seems that you have tried to perform an illegal workflow operation.If you think this message is wrong, please contact your JIRA administrators.
I can't see logs. Does anybody know what is wrong? When I comment this line "issue.setCustomFieldValue(Approvers, newApprovers)" alert disappears.
Here on this page is example only for (single select) user picker.
Thank You!
You should use IssueService, which will do the reindexing for you. You should be able to replace your script with the one below:
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueService = ComponentAccessor.getComponent(IssueService) def approvers = customFieldManager.getCustomFieldObjectByName("MultipleUserPicker") def issue = issue as Issue def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def issueInputParameters = issueService.newIssueInputParameters() // Adding the user names here issueInputParameters.addCustomFieldValue(approvers.id, "user1", "user2") def updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters) if (updateValidationResult.isValid()) { issueService.update(user, updateValidationResult) }
I changed names of CustomField and users but it is not working.
This script generates no error, but field is empty. =((
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I know what happened, user must have a permission to edit? I'll check it...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible to select another user, not current logged in?
"Edit issue" is deprecated in our project, we are changing fields in transitions. Each field in its own transition (very strict).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes if the logged in user does not have issue edit permissions it can't be done. You should run it as a user with the correct permissions. You can get a user like so:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserManager def userManager = ComponentAccessor.getComponent(UserManager) def user = userManager.getUserByKey("userkey")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
I'm trying to do the same, but what i have is an array / list of users (= MemberUsernames) of which i do not know how many they will be.
Do you have a suggestion on how i could do that?
issueInputParameters.addCustomFieldValue(approvers.id, MemberUsernames)
def updateValidationResult = issueService.validateUpdate(currentReporterFull, issue.id, issueInputParameters)
if (updateValidationResult.isValid()) {
issueService.update(currentReporterFull, updateValidationResult)
}
}
Thanks and best regards
Thomas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I changed names of CustomField and users but it is not working.
This script generates no error, but field is empty.
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.