Forums

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

ScriptRunner, Groovy, Return reporters issues

Knut Arne Ristebråten
Contributor
January 19, 2018

I am new to this so sorry if this is a noobie question - I have very little experience atm with groovy.

Hoping to get some help with this.

What I am after, is a panel added to a issue that returns the last issues (e.g. 10) that the reporter have created.

I found that the Scriptrunner can use the panel with Script Fragments -> Show a web panel.
But I got no idea how to write this code (Privder class/script field).

Can someone help me with the code? Seeing code like this also helps me in understanding this beter.

2 answers

0 votes
Erik Ekengren
Contributor
August 1, 2025

Hi! 

I realize I am answering an old question but maybe someone scratching your head and, like me, stumbled upon this thread. I found a way to do this using UI fragments.

First, create a UI fragment  as type Custom Web Panel (show a web panel). Then add any conditions (for example if you only want to do this in specific projects or for specific users) and then add this script:

import com.adaptavist.hapi.jira.issues.Issues

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.RendererManager


def rendererManager = ComponentAccessor.getComponent(RendererManager)

def fieldLayoutManager = ComponentAccessor.fieldLayoutManager

def currentIssue = context.issue as Issue


Issues.search("""project = '${currentIssue.projectObject.key}'and reporter = '${currentIssue.reporter.name}' and key != '${currentIssue.key}' ORDER BY created DESC""").take(10).toList()

.each { issue ->

    def fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem("key")

    def renderer = rendererManager.getRendererForField(fieldLayoutItem)

    writer.write("${renderer.render(issue.key, null)} - ${renderer.render(issue.summary, null)}<br/>")

}

This will display the last 10 issues the reporter has created in this specific project. If you want to display anything else then just edit the query:
Issues.search("""project = '${currentIssue.projectObject.key}'and reporter = '${currentIssue.reporter.name}' and key != '${currentIssue.key}' ORDER BY created DESC""").take(10).toList()

 

Edit this query to your needs. If you want to display more or less issues just edit the 10 in the .take(10).toList().

I hope this will help anyone out there with the same problems I was having.
0 votes
Krisztian Kovacs
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.
January 19, 2018

hi there,

this might help you get started with some basics: https://scriptrunner.adaptavist.com/4.3.4/jira/fragments/WebPanel.html#_conditions

but what I would do it:

I hope this helps a bit.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events