Is there a way to show the difference between 2 different multi-checkbox custom fields using Scripted Fields?

Peter Bengov Community Champion Nov 03, 2014

I have 2 custom fields with the same values in both. I'd like to compare the values and show in a 3rd (scripted) field what are the values that I have checked in field #1 and don't have checked in field #2.

Moreover, if would help to know how can a loop over the multicheckbox field and access each value there. 

Thanks

1 answer

1 accepted

0 vote
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field1Vals = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("First Field")) as List<Option>
field1Vals*.value

The last line gives you the string values of field 1, eg \["Yes, "No", "Maybe"]

Do the same for field two...

leftFields.intersect(rightFields)

will give you the common ones, so you can just loop through and render the differences nicely.

Peter Bengov Community Champion Nov 06, 2014

Thank you Jamie. Writing below some more code I used, maybe will help future user as well. {code:} import com.atlassian.jira.component.ComponentAccessor; def customFieldManager = ComponentAccessor.getCustomFieldManager(); List field1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("field1")) as List<String>; List field1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("field1")) as List<String>; field1*.value; field1*.value; // this how I got to know if the checkbox value (label) is indeed checked (looped me lists for this): if (field1*.value.contains("label1") == true) {code}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

121 views 4 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you