Hi,
I want to set a multi user picker as assignee in a JIRA Software Project and I am using the code below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObjectByName("Approver (QA)")
ApplicationUser user = issue.getCustomFieldValue(brm_field) as ApplicationUser
UserManager userManager = ComponentAccessor.getUserManager();
issue.setAssignee((user))
An error message is displayed when i do the transition and the script is in the last position.
Thanks
Swarna
Hello,
Try a code like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObjectByName("Approver (QA)")
def user = issue.getCustomFieldValue(brm_field)
UserManager userManager = ComponentAccessor.getUserManager();
issue.setAssignee(user[0])
Exactly this
For your information @Swarna Radhayou can't set a multiuser picker value (collection) into a single user picker (not collection), so you need to take a single value. With the [0] you pick the first value of the collection.
Also, the code can be cleaned, it would be enough with this:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObject("Approver (QA)")
def user = issue.getCustomFieldValue(brm_field)
issue.setAssignee(user[0])
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.
It is a static compilation error. It must work with this error as well. But if you want to get rid of this error, you can write like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObject("Approver (QA)")
List<ApplicationUser> user = issue.getCustomFieldValue(brm_field)
issue.setAssignee(user[0])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi I am getting error and the script is failing.
2018-09-05 09:22:10,469 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-09-05 09:22:10,470 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITCRD-3883, actionId: 91, 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 Script1780.run(Script1780.groovy:13)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It means that the Approver (QA) custom field does not exist in your Jira.
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.
That is right. It must be like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObjectByName("Approver (QA)")
List<ApplicationUser> user = issue.getCustomFieldValue(brm_field)
issue.setAssignee(user[0])
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 same as above and I am getting on the line .
issue.getCustomFieldValue(brm_field)
"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure it is same? You can log the reference of the custom field:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def brm_field = customFieldManager.getCustomFieldObjectByName("Approver (QA)")
log.error(brm_field)
List<ApplicationUser> user = issue.getCustomFieldValue(brm_field)
issue.setAssignee(user[0])
What value is logged?
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.
Good to hear! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev I tried using the same you have provided still it is not setting the assignee from a multi-user picker custom field. I have this post function used in create transition as the last line.
@Swarna Radha When you say, at the last position, do you mean to have the post function the "Custom script post-function (inline script)" at the last position or you are mentioning about in the groovy script?
Any suggestion is appreciated.
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.