Forums

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

Create a custom field called count with Scriptrunner

Mehvish Patel June 3, 2019

I have to create a custom field called 'Count' to get the count of labels for a set of issues. I have to create it with Scriptrunner, for a specific project. I just want the count of labels. i'm completely new to Jira, any help would be appreciated. Where should i start writing the code, what should be done? Kindly help. 

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Champion
June 3, 2019

Hi @Mehvish Patel , welcome to the community.

I would suggest you create a Script field (GG > Script Fields) : 

image.pngChoose the template "Number field" and use this as inline script : 

def labels = issue.getLabels()
return labels == null ? 0 : labels.size()

Then configure the context and screens as with any other field to display it on the right project/screens by clicking the cog.

Hope that helps.

Antoine

Mehvish Patel June 3, 2019

Hi Antoine, 

Thanks for the answer, but it seems like i have to enter the issue key for the preview/add. But the thing is i want to view this for multiple issues is there any way that is possible?

Antoine Berry
Community Champion
June 3, 2019

You need the issue key to preview, It will show the value returned for this specific issue. If you add as is, the field will show on issues as configured in the context/fields.

Antoine

Mehvish Patel June 3, 2019

Okay thanks for ur help!

Like Antoine Berry likes this
Mehvish Patel June 3, 2019

Hey Antonie,

Could you help me with one more query....in this above code if i want to view the count of the labels - remediation owner wise how can i do that? 

In my dashboard the name of the remediation owner is occurring multiple times...i only want it to appear once...is that possible?

Antoine Berry
Community Champion
June 3, 2019

What do you mean by "remediation owner" ? If you could include a screenshot that would help.

Mehvish Patel June 3, 2019

Oh! Apologies. Please find the screenshot:

Capturenew.PNG

Antoine Berry
Community Champion
June 3, 2019

I am not sure to understand. I guess Remediation owner is a user picker custom field ? If it is a single user picker, you will have only one user per issue, so that should be fine. 

Or maybe you want to group issues by remediation owner ? Please provide a screenshot of your board, that help me to figure out. :)

Mehvish Patel June 3, 2019

Remediation owner is a custom field so i aiming for something like this:

new.PNG

but i do not want the name to be repeated. For one user the count of the label should be shown once.

Antoine Berry
Community Champion
June 3, 2019

To my understanding this is not possible out of the box. You have to check for appropriate gadgets in your dashboard (maybe something exists in cloud). Otherwise you have 2 solutions :

  • Export your filter result and group by your remediation owner in excel.
  • Look for apps in the marketplace.

Antoine

Mehvish Patel June 4, 2019

Oh okay, do you think we can change the JQL a bit and try getting the result from that? Is that possible?

Antoine Berry
Community Champion
June 4, 2019

Unfortunately no. JQL filters return a set of issues. But they cannot aggregate data from issues (apart from a few exceptions from scriptrunner plugin...). So you will always get a set of individual issues.

My advice would be to create an excel file which transforms your data as you wish. You can also create a macro that retrieves jira issues directly in excel, which would prevent you from exporting manually in jira. Take a look at that topic.

Antoine 

Antoine Berry
Community Champion
June 4, 2019

@Mehvish Patel , actually you can use aggregateExpression, for example : 

project = XXX and assignee = patel_m and issueFunction in aggregateExpression("customfield_13400.sum()")

(you can use average instead of sum for the mean value)

image.png

Make sure your script field has Number Searcher for this to work : 

image.png

Maybe that is an acceptable middle ground ?

Antoine

Mehvish Patel June 10, 2019

Hi Antoine,

I think the above solution is good to go, the only problem is i can't get the number searcher field, i.e it seems it isn't present there. Any reason it's that way can you tell me?

Antoine Berry
Community Champion
June 11, 2019

Hi @Mehvish Patel , 

You should pick number searcher for the script field, do you not have this option ? 

image.png

Mehvish Patel June 11, 2019

Yes, found it. I was on a different page hence the confusion. Thanks for all your help.

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer