Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

I want to fetch data and compare between multi select user fields

aditya442
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 29, 2022

Hi,

I have 3 multi select user field "Approvers" , "Pending Approvers" and "Approved By".

My requirement is - Every time an approver approves, I need to remove the name from Pending Approvers.

This is my code and it gives me error in the last line. I am not sure what did I miss here. can someone help?

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Category
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject("XXX-215")
def issue=Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def approvedBy = customFieldManager.getCustomFieldObject("customfield_10760");
def specApprovers = customFieldManager.getCustomFieldObject("customfield_10607");

log.info("approvedBy"+approvedBy)
log.info("specApprovers"+specApprovers)

//List approvedUsers = approvedBy? (List)issue.getCustomFieldValue(approvedBy) : "Field doesn't exist"
List approvedUsers = (List)issue.getCustomFieldValue(approvedBy)
List approvers = (List)issue.getCustomFieldValue(specApprovers)

def pendingApprover=approvers
if (approvedUsers)
pendingApprover.removeAll(approvedUsers)

log.info("Approvers"+approvers)
log.info("Approvedby"+approvedUsers)
log.info("diff"+pendingApprover)

def changeHolder = new DefaultIssueChangeHolder()
//def finalvalue = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Pending Approvers"}
def finalvalue = customFieldManager.getCustomFieldObjectsByName("Pending Approvers")
finalvalue.updateValue(null, issue, new ModifiedValue(finalvalue, pendingApprover),changeHolder)

 

Error 

image.png

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
aditya442
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 29, 2022

.

TAGS
AUG Leaders

Atlassian Community Events