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.