Forums

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

Get list of issues from a project and check custom field values

Justin G
December 20, 2019

Using Script Runner and Behaviors

I am looking to pull all issue id's for a specific project and then for each issue, compare one of its custom field values to a string. This string will be whatever the user entered into that custom field for that specific issue on the form (CR Number).  If the custom field value (from all the other issues) is equal to that string (what was entered), then I need to raise an error stating that the value needs to be changed (no duplicates of "CR Number" are allowed)

What I have so far is I am able to get the list of all issues from my project and I believe all Issue objects have their field values in the said object.  

So now I want to do my comparison:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;

def issueMgr = ComponentAccessor.getIssueManager()
def issues = issueMgr.getIssueObjects(issueMgr.getIssueIdsForProject(10000))

//Here - how do I get what was entered into the custom field and compare it to all the CR NUMBER fields of the returned Issue item list (issues)

def input = getFieldById("customfield_10302")
def val = input.getValue() as String

for (int i = 0; i < issues.size(); i++){

if(issues[i].getCustomFieldValue(getFieldById("customfield_10619").equals(val))){
  //raise an error here and user must try a different value
}

}

1 answer

0 votes
Sam Hall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 6, 2017

Suggest an answer

Log in or Sign up to answer