Forums

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

Scriptrunner to compare two Select List (single choice) fields

Kristin Palmer
Contributor
May 27, 2021

Hi

I have two custom fields that are type Select List (single choice):

  • Health (This Week) - customfield_21107
  • Health (Last Week) - customfield_21108

Both custom fields have the same options available for selection

  • Not Started
  • On Track
  • Off Track
  • Done

I would like to run a query where I can return a list when Health (This Week) = Health (Last Week). I would also like to be able to run the inverse query, where Health (This Week) != Health (Last Week).

I have tried:

issueFunction in issueFieldMatch("", "customfield_21108", customfield_21107)

but I don't get any results (even though I should). I think the third argument isn't being resolved?

I've also tried: 

issueFunction in expression("", "customfield_21108 = customfield_21107")

 but I don't get the results I expect. Interestingly I get the same results with "=" or "!="

 

Any suggestions?

1 answer

1 accepted

2 votes
Answer accepted
Ioana
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 Leaders.
May 27, 2021

Hi Kristin,

I don't think those work with select list custom fields, but only with number and dates, which support comparison.

You could create a script to loop over each issue in a given JQL search ( like cf[21107] is not empty and cf[21108] is not empty ).

The script should return the issuekey for each issue where the cfs have the same value.

 

If you don't want to create a script for that, you could simply use the JQL below, since there aren't maby values to compare:

(cf[21107] = "Not Started" AND cf[21108] = "Not Started" ) OR (cf[21107] = "On Track" AND cf[21108] = "On Track" ) OR (cf[21107] = "Off Track" AND cf[21108] = "Off Track" ) OR (cf[21107] = "Done AND cf[21108] = "Done" )

To see where they are not the same, save the above JQL in a filter and create another one like:

cf[21107] is not empty and cf[21108] is not empty AND filter != 1234

Replace 1234 with the ID of the filter you saved. It should return all issues where the cfs are not empty and not equal.

 

Regards,

Ioana

Kristin Palmer
Contributor
May 30, 2021

I implemented the JQL and filters - works perfectly. Thanks Ioana!

Suggest an answer

Log in or Sign up to answer