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.
[{
"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"
}
]
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.