Unable to set the approver name into another mulitple user picker

Swarna Radha August 25, 2018

Hi,

I want to set the approver name in to a custom field B (mulitple user picker).

 

Is this possible?

Thanks

Swarna

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2018

There's a very similar question (with correct answer that will get you pointed in the right direction) over at https://community.atlassian.com/t5/Jira-questions/I-need-help-copying-the-assignee-field-to-a-user-picker-custom/qaq-p/872633#M279889

Swarna Radha August 25, 2018

Hi Nic,

 

I am getting error on the following line

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser

log.setLevel(org.apache.log4j.Level.DEBUG)


CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def userCf = customFieldManager.getCustomFieldObjectByName("Approved by (Dev)")
List<ApplicationUser> userAlreadyInCustomField = issue.getCustomFieldValue(userCf) //getting error
log.debug("User list: $userAlreadyInCustomField");
issue.setCustomFieldValue(userCf, userAlreadyInCustomField);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

 

thanks

Swarna

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2018

"getting error" does not tell us anything about the problem.  What is the error?

Swarna Radha August 26, 2018

Hi @Nic Brough -Adaptavist-,

 

I am unable to set the person who did the transition in the custom field .

Please see my code:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption


IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Approved by IT- Appli Dev LM/TL");
List<ApplicationUser> users;
if(users == null)
users = new ArrayList<>();

users.add(ComponentAccessor.getUserManager().getUserByName("Username"))
issue.setCustomFieldValue(CF, users);

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

 

Error message:

2018-08-27 08:49:41,594 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-08-27 08:49:41,594 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITCRD-3433, actionId: 91, file: <inline script>
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.atlassian.jira.user.ApplicationUser
 at com.atlassian.jira.issue.customfields.impl.UserCFType.getDbValueFromObject(UserCFType.java:83)
 at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:143)
 at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
 at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410)
 at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655)
 at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:214)
 at com.atlassian.jira.issue.IssueManager$updateIssue$4.call(Unknown Source)
 at Script541.run(Script541.groovy:25)

Thanks
Swarna
Like Johannes likes this
Yana Stoliarova
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 19, 2024

I am getting the error too. I tried (I believe) everything - no luck.

Suggest an answer

Log in or Sign up to answer