Scriptrunner - Accessing issue information in a web fragment?

Wesley Stewart September 20, 2023

Losing my mind a little bit.  I made a new web fragment that displays on: alt.jira.view.right.context

For the condition, I automatically have access to JiraHelper and Issue classes/variables.  Works fine...

For the "Provider class/script" portion, I dont have either of those.  I am trying to get the issues Assignee Email address, Reporter, email address, key, and a few other items.

Most things I see online say to:

(Sorry dont know how to submit a comment block)

import com.atlassian.jira.issue 
- OR -
import com.atlassian.jira.issue.Issue

but these don't work and I get an "Import is never referenced".

 

So I tried:

import com.atlassian.jira.component.ComponentAccessor
def cf = ComponentAccessor.fieldManager.getField('reporter').getId()

But this just returns "reporter"
What am I missing?  How do I access the issues fields in the web fragment?

2 answers

1 accepted

0 votes
Answer accepted
Wesley Stewart October 2, 2023

This worked.  Although I had the hardest time finding out "context" and how to use it.  I also had trouble finding the correct libraries to import, so I used

import com.atlassian.jira.issue.*

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
def issue = context.issue as Issue

def issueAssignee = issue.assignee?.getEmailAddress().toString()
def issueReporter = issue.reporter?.getEmailAddress().toString()
def issueReporterName = issue.reporter.getDisplayName().toString().split(', ')
def issueAssigneeName = issue.assignee.getDisplayName().toString().split(', ')
def issueKey = issue.getKey().toString()
def firstNameR = issueReporterName[1]
def lastNameR = issueReporterName[0]
def userNameR = issue.reporter.getUsername()
def firstNameA = issueAssigneeName[1]
def lastNameA = issueAssigneeName[0]
def userNameA = issue.assignee.getUsername()
0 votes
Hauke Bruno Wollentin
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.
September 20, 2023

Are you using a custom web item?

This need to trigger an URL which could be a REST endpoint in ScriptRunner. It is possible to use variables in the actual configured URL like:

https://myjira.foo.bar/rest/scriptrunner/latest/custom/foobar?issueKey=${issue.key}
Wesley Stewart October 2, 2023

leaving the java api to have to hit/authenticate to a http restApi seems excessive.

I found a much easier way in the java API.  However I had a REALLY hard time finding the "context" variable and it's methods used in a fragment and how to use it.  I went through dozens of posts and found one with it referenced...

I had to use a wildcard here, because I couldnt find the correct combination of imports.  But it worked...

import com.atlassian.jira.issue.*

 

This ultimately worked fine... I needed variables from the reporter and the assignee to do some other customizations.  This is how I snagged them:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
def issue = context.issue as Issue

def issueAssignee = issue.assignee?.getEmailAddress().toString()
def issueReporter = issue.reporter?.getEmailAddress().toString()
def issueReporterName = issue.reporter.getDisplayName().toString().split(', ')
def issueAssigneeName = issue.assignee.getDisplayName().toString().split(', ')
def issueKey = issue.getKey().toString()
def firstNameR = issueReporterName[1]
def lastNameR = issueReporterName[0]
def userNameR = issue.reporter.getUsername()
def firstNameA = issueAssigneeName[1]
def lastNameA = issueAssigneeName[0]
def userNameA = issue.assignee.getUsername()
shamanth.umesh October 30, 2023

Hi @Wesley Stewart ,

How do you display these values on the web panel? I tried the ${variable_name} in the writer.write function but it doesn't display anything..

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events