Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner - Accessing issue information in a web fragment?

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

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.
Sep 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}

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
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Oct 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