Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Count number of selections in a multiselect

Hi

I am using Adaptavist Scriptrunner

I have some listener code to calculate an issue score based on the values selected in various custom fields.  One of the calculations is to count the number of options selected in a custom multiselect field and based on the number add a certain value to the score field.

I don't seem to be able to find any sample code for this.  Would appreciate some assitance.

Dave

1 answer

0 votes

The options in a multiselect are held in a collection, so you can actually just use size() to get it!

def myCf = customFieldManager.getCustomFieldObjects(issue).find { it.name == "My field name" }

def fieldContent = issue.getCustomFieldValue(myCf)
def numberOfSelections = fieldContent.size()

Hi Nic

 

Sorry - I only saw your response now.

If I try your code I get an syntax error on fieldContent.size().  Please see attached screenshot.  

what am I missing?

 

Regards

 

Dave Cuff

Hmm.  Could you try forcing the type by replacing the "def" on line 73 with "Collection" - this should stop the weak-typing that Groovy claims is useful, and force the variable to be seen as the type that it really is always going to be.

(I've come to hate languages that isn't strongly-typed or minimally typed - so... many... stupid... bugs...)

Looks like we have a challenge.  Error in below screenshot.  NB we are on JIRA 7.13.5 and Scriptunner 6.0.0.  Not sure if this could be causing the error.

I have the following import commands.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.customfields.option.LazyLoadedOptionAnnotation (3).png

Try Collection,  not collection.

Ooops - sorry about that.

I did and the error has now changed.  Please see below.

Annotation (4).png

hello,

Were you able to solve the problem?

Thank you :)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Jira issue check and more advanced commit verifications for Bitbucket DC

Pre-receive hooks that verify the Git commit message, the modified files, and implement similar code change controls used to be requirements of large enterprises working in regulated industries only....

37 views 0 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you