We use a Listener Script to sum the total Story Points up tp the Epic. Lately we have been seeing an error that we have not been able to debug. It does not happen for every issue.
The error:
ERROR - Cannot get property 'issues' on null object on line 13
The code:
// Get the ID of the fields for Story Points and Epic Link
def storyPointsField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points'}.id
def epicLinkField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Epic Link'}.id
def storyPointsTotalField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points Total'}.id
// Retrieve all the issues in this issues' Epic
def epicKey = issue.fields."${epicLinkField}"
def storyPoints = issue.fields."${storyPointsField}"
logger.info("Epic Key is: " + epicKey)
logger.info("Story Point is: " + storyPoints)
if (epicKey != null) { //This is to check if the event.issue's epic is null or not
def issuesInEpic = get("/rest/agile/1.0/epic/${epicKey}/issue")
.asObject(Map)
.body
.issues as List<Map>
logger.info("Total issues in Epic for ${epicKey}: ${issuesInEpic.size()}")
// Sum the estimates
def estimate = issuesInEpic.collect { Map issueInEpic ->
issueInEpic.fields."${storyPointsField}" ?: 0
}.sum()
logger.info("Summed estimate: ${estimate}")
// Now update the parent Epic
def result = put("/rest/api/2/issue/${epicKey}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"${storyPointsTotalField}": estimate,
]
])
.asString()
// check that updating the parent issue worked
assert result.status >= 200 && result.status < 300
}
The error occurs at the bolded line in the code. I am looking for help on two items:
1. How do I debug the issue to see which issue/field is returning a null value
2. Can I limit the data being returned to just the Story Points field and would that help resolve the null "issues" error?
Would you have a moment to review the script above?
The script was working, with an occasional error, now the error is on most runs. I am unsure how to debug the get statement to find the "null"
Hi @JT
I would advise you to raise a ticket in our Support Portal together with the Correlation ID from hen the script if failing for us to check further on our end.
Is the issue type is an Epic when the script runs as it would only run on Epic issues from the script.
Also, Does the epicKey contain a value as if this Null. Then, your REST call would not return an issue. Can you include the REST call in an IF check to see if this value is Null so that the REST call is not made when this value is Null.
Id say maybe ask them to raise a ticket in our support portal with a correlation ID from when the script fails, also I would ask is the issue type an epic when the script runs as it would only run on epic issues from that script
Thank you.
Kind Regards
Kate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @JT , I would try to change
def issuesInEpic = get("/rest/agile/1.0/epic/${epicKey}/issue")
.asObject(Map)
.body
.issues as List<Map>
to
def issuesInEpic;
def issuesInEpicBody = get("/rest/agile/1.0/epic/${epicKey}/issue")
?.asObject(Map)
?.body
if(issuesInEpicBody?.issues){
issuesInEpic = issuesInEpicBody?.issues
}else{
return
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Martin Bayer _MoroSystems_ s_r_o__
Thank you for the help. If I change my code as you suggested, I get e new error stating "the variable [body] is not undeclared"
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.
Hi @Martin Bayer _MoroSystems_ s_r_o__
Still throwing an error:
2021-03-15 21:17:31.022 ERROR - No such property: body for class: Script1 on line 17 2021-03-15 21:17:31.040 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @JT , I just tested following code and it works nice (tested with epic which contains issue and epic with no issues:
def issuesInEpic = get("/rest/agile/1.0/epic/CK-3/issue")
?.asObject(Map)
?.body
?.issues as List<Map>
But I can see, there is another body property/method used with put method. Can you try to remove empty spaces and put everything to one row?
// Now update the parent Epic
def result = put("/rest/api/2/issue/${epicKey}").queryString("overrideScreenSecurity", Boolean.TRUE).header('Content-Type', 'application/json').body([
fields: [
"${storyPointsTotalField}": estimate,
]
]).asString()
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.