Forums

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

How to read Issuetype field from script runner

serge calderara
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.
March 3, 2021

Dear all,

I am using Script runner under Jira Cloud on which I need to convert Script Runner Script from our server side .

From our initial script we are checking different field like:

  • issue IssueType
  • issue assignee
  • issue assignee DisplayName :


Actually I am retrieving for instance the information as below :

// Fetch the issue object from the key
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body

// Get all the fields from the issue as a Map
def fields = issue.fields as Map
def issueType=fields.issuetype as Map

def project= fields.project as Map
return project.key

Based on code snipet above, I am succesfully returning the project key

But I am not able to get the issueType name, any idea how to get it correcttly?

regards

serge

 

2 answers

1 accepted

1 vote
Answer accepted
serge calderara
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.
March 3, 2021

Hello @Hana Kučerová , I manage to get it the follwoing way only

def issue = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

def IssueType= issue.body.fields.issuetype.name

0 votes
Hana Kučerová
Community Champion
March 3, 2021

Hi @serge calderara ,

please try:

fields.issuetype.name

or using your variable

issueType.name
serge calderara
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.
March 3, 2021

hello @Hana Kučerová , I have tried and received the following exception

// Get all the fields from the issue as a Map
def fields = issue.fields as Map
return fields.issuetype.name

MissingPropertyException: No such property: fields for class: io.github.openunirest.http.HttpResponse

Any idea ?

serge calderara
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.
March 3, 2021

Hello @Hana Kučerová , I manage to get it the follwoing way only

def issue = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

def IssueType= issue.body.fields.issuetype.name

Suggest an answer

Log in or Sign up to answer