I have one issue and two custom fields type MultiUserPicker: MUP1, MUP2.
initially
MUP1 = (user1, user2, user3)
MUP2 = null
in the post-function I need to do
MUP1 = MUP1 - CurrentUser
MUP2 = MUP2 + CurrentUser
if current user exist in first field.
as a result
MUP1 = null
MUP2 = (user1, user2, user3)
I broke my brain, but did not find methods.
May be Class MultiUserCFType and updateValue(customField, issue, value)? But how?
Does anyone know how to do?
Also, Happy New Year! :)
Community moderators have prevented the ability to post new answers.
Here is code exmple to start with:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.user.ApplicationUser ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser() CustomField customField1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FieldName1") CustomField customField2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FieldName2") //Delete user List<ApplicationUser> users = new ArrayList<>(); for(ApplicationUser multiUseruser: (List<ApplicationUser>) issue.getCustomFieldValue(customField1)){ if(!multiUseruser.getKey().equals(user.getKey())){ users.add(multiUseruser) } } issue.setCustomFieldValue(customField1, users); //add user issue.setCustomFieldValue(customField2, ((List<ApplicationUser>) issue.getCustomFieldValue(customField1)).add(user))
Hello, Vasiliy.
Your code gives the conversion error types.
Can you help solve this?
Attlassian sends to the article: https://confluence.atlassian.com/jira/upgrading-workflow-plugins-for-jira-3-2-116700.html
but that's about 3 versions of the Jira, but we have 6.
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Collection at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:41) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:854) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:522) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:504) at com.atlassian.jira.workflow.function.issue.GenerateChangeHistoryFunction.execute(GenerateChangeHistoryFunction.java:65) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446) at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564) ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you provide where this error raise? Which line?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
error line
issue.setCustomFieldValue(customField2, ((List<ApplicationUser>) issue.getCustomFieldValue(customField1)).add(user))
in particular
issue.getCustomFieldValue(customField1)).add(user))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, lets try this:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.user.ApplicationUser ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser() CustomField customField1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FieldName1") CustomField customField2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FieldName2") //Delete user List<ApplicationUser> users = new ArrayList<>(); for(ApplicationUser multiUseruser: (List<ApplicationUser>) issue.getCustomFieldValue(customField1)){ if(!multiUseruser.getKey().equals(user.getKey())){ users.add(multiUseruser) } } issue.setCustomFieldValue(customField1, users); //add user issue.setCustomFieldValue(customField2, ((List<ApplicationUser>) issue.getCustomFieldValue(customField1)).add(users))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<p>I'm training to use this script, but its not deleting my currentUser .
workflow show me this message</p>
2017-06-07 12:43:39,622 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-06-07 12:43:39,625 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: BRCH-53, actionId: 821, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$2.call(Unknown Source) at Script281.run(Script281.groovy:18)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i'm training to use this script, but its not delete my current user . i receive this message
2017-06-07 12:43:39,622 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-06-07 12:43:39,625 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: BRCH-53, actionId: 821, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$2.call(Unknown Source) at Script281.run(Script281.groovy:18)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you get the current content of the field, it will return a list type object, with each element of the list being a user. You should be able to add or remove users on the list, and then post the modified list back into the custom field value.
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.