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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.