Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update the Approvers custom field with two values?

admin
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!
January 31, 2019

Hi there! 

I'm trying to add one more approver to the Approvers custom field using ScriptRunner addon.

What I have: 
 - Create transition
 - The automatically populated Approvers custom field with the Line Manager Jira User Id

I need: 
To get the user id from the financeManager role and simply add this to the Approvers custom field to get two user ids in Approvers.

Looks like the code returns the necessary array. However, when I'm trying to create a new issue, I have got only the line manager user id in the Approvers field.

What's wrong?

ProjectRoleManager projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager.class) as ProjectRoleManager
ProjectRole financeRole = projectRoleManager.getProjectRole("Finance Manager")
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(financeRole, issue.getProjectObject())
def financeManager = actors.getUsers().toList()?.first();

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def approversField = customFieldManager.getCustomFieldObjectByName("Approvers")
List<ApplicationUser> approvers = (List<ApplicationUser>)issue.getCustomFieldValue(approversField)

log.info(approvers); //get [line manager user id]

approvers.add(financeManager);

issue.setCustomFieldValue(approversField, approvers) //get only line manager user id

log.info(approvers); //get [line manager user id, finance manager user id]

Thanks in advance. 
 

1 answer

1 accepted

0 votes
Answer accepted
admin
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!
February 1, 2019
approversField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(approversField), approvers), new DefaultIssueChangeHolder())

Suggest an answer

Log in or Sign up to answer