.queryString("fields", "customfield") does not work in Scriptrunner from Jira Cloud

Antoine _Klee Group_ October 22, 2021

Hello,

I want to implement a scripted field similar to the one shown in the example code available on Adaptavist's website.

The thing is that this code is not actually working.

After investigation, it seems that calling the rest api with .queryString("fields", ) is not able to return an array with a customfield value. (it works well with all native fields).

See inputs and outputs

if (issue.fields.issuetype.name == "Epic") {
def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>

def ChiffrageTRATotal = 0

// Get all issues below the the Epic Issue
def allChildIssues = get("/rest/agile/1.0/epic/${issue.key}/issue")
.queryString("jql", "parentEpic =${issue.key}")
.queryString('fields', 'priority')
.asObject(Map)
.body
.issues as List<Map>

return allChildIssues
}

Returns the field 

[{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"priority": {
"iconUrl": "https://<mysite>.atlassian.net/images/icons/priorities/low.svg",
"id": "4",
"name": "P3",
"self": "https://<mysite>.atlassian.net/rest/api/2/priority/4"
}
},
"id": "16615",
"key": "SEL-1669",
"self": "https://<mysite>.atlassian.net/rest/agile/1.0/issue/16615"
}, {
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"priority": {
"iconUrl": "https://<mysite>.atlassian.net/images/icons/priorities/blocker.svg",
"id": "2",
"name": "P1",
"self": "https://<mysite>.atlassian.net/rest/api/2/priority/2"
}
},
"id": "16833",
"key": "SEL-1712",
"self": "https://<mysite>.atlassian.net/rest/agile/1.0/issue/16833"
}
]

 

But
if (issue.fields.issuetype.name == "Epic") {
def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>

def ChiffrageTRATotal = 0

// Get all issues below the the Epic Issue
def allChildIssues = get("/rest/agile/1.0/epic/${issue.key}/issue")
.queryString("jql", "parentEpic =${issue.key}")
.queryString('fields', 'customfield_xxxx')
.asObject(Map)
.body
.issues as List<Map>

return allChildIssues
}
With customfield_xxxx being a valid non-empty custom field on the child issues of my epic.
Returns:
[{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "16615",
"key": "SEL-1669",
"self": "https://<mysite>.atlassian.net/rest/agile/1.0/issue/16615"
}, {
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "16833",
"key": "SEL-1712",
"self": "https://<mysite>.atlassian.net/rest/agile/1.0/issue/16833"
}
]
With no mention to the field array nor customfield_xxxx.
How to fix that?
Thanks.

2 answers

0 votes
Damian Wodzinski
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.
October 27, 2021

I am not sure, why they use this: 

/rest/agile/1.0/epic/${issue.key}/issue

Tried to find it in documentation with no luck.

I would suggest using simple JQL query searcher instead:


def searchReq = get('/rest/api/3/search')
.queryString('jql', parentEpic =${issue.key})
.queryString('fields', 'customfield_xxxx')
.asObject(Map)

return searchReq.body.issues
Antoine _Klee Group_ October 27, 2021

Thanks for your solution Damian.

0 votes
Antoine _Klee Group_ October 25, 2021

As a workaround, the fields returned can be filtered within the URL just as shown here.

So for my example that would be 

def allChildIssues = get("/rest/agile/1.0/epic/${issue.key}/issue?fields=customfield_10231,customfield_10232")

That is less clean but works. 

Suggest an answer

Log in or Sign up to answer