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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Edited

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
TAGS
AUG Leaders

Atlassian Community Events