Forums

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

How to get Sprint Name using ScriptRunner Cloud Listener?

alexmears
Contributor
August 23, 2018

Currently

Our Sprint names follow a YYMMDD convention.

Goal

We want to take the Sprint Name and populate a Date custom field in JIRA that we can then compare to Due Dates.

ScriptRunner Listener Script


// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

def inputid = customFields.find { it.name == 'Sprint' }?.id
def outputid = customFields.find { it.name == 'TESTING Expected Prod Deployment Date' }?.id
def projectKey = "OP"

if (issue == null || ((Map)issue.fields.project).key != projectKey) {
logger.info("Wrong Project \${issue.fields.project.key}")
return
}

def input = issue.fields[inputid].Get("name") as String

if (input == null) {
logger.info("Calculation using \${input1} and \${input2} was not possible")
return
}

def output = Date.parse("yyMMdd", input)

if (output == (issue.fields[inputid] as Date)) {
logger.info("already been updated")
return
}

put("/rest/api/2/issue/\${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputid): output
]
])
.asString()

Issue

The script fails at def input = issue.fields[inputid].Get("name") as String since .Get("name") is how I would imagine I would get the value from the Sprint, but it doesn't work that way.

I don't have much java expertise, so would appreciate any pointers anyone might have.

1 answer

1 accepted

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 28, 2018

Hi Alex,

Thank you for your question.

I can confirm that to get the sprint value off an issue that you need to use the Jira Software API's rather than the standard get issue api as this just stores the sprint details as text. 

I have created a sample script located here which you can run in the script Console in order to get the name of the sprint on a specified issue. 

You will be able to use this sample script in order to modify your code to get the sprint value which you require. 

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

alexmears
Contributor
August 28, 2018

Thank you for the response. The script returns the following error at line 21:

[Stack type checking] - No such property: name for class: java.lang.Object

name not a property of sprint.png

alexmears
Contributor
August 28, 2018

WOW, the error message in the script console is incorrect. This script works, which means my other scripts were working before but I wasn't running them due to the error message. 8hrs down the drain.

Thank you for your help.

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 28, 2018

Hi Alex,

 

Thankyou for confirming that your issue has been resolved.

I can confirm that Static Type Checking errors are just warnings where the compiler does not understand the code as described here and that scripts will still run with these type checking warnings.

Kristian

Suggest an answer

Log in or Sign up to answer