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.
Hi @Mehvish Patel , welcome to the community.
I would suggest you create a Script field (GG > Script Fields) :
Choose 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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you mean by "remediation owner" ? If you could include a screenshot that would help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Remediation owner is a custom field so i aiming for something like this:
but i do not want the name to be repeated. For one user the count of the label should be shown once.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh okay, do you think we can change the JQL a bit and try getting the result from that? Is that possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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)
Make sure your script field has Number Searcher for this to work :
Maybe that is an acceptable middle ground ?
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mehvish Patel ,
You should pick number searcher for the script field, do you not have this option ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, found it. I was on a different page hence the confusion. Thanks for all your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.