def transitionID = '10000'
def parentIssueName = 'customfield_10001'
def parentKey = 0
// Get the parent key, based on the issue type
if (((Map) issue.fields.issuetype)?.name == 'Sub-task') {
parentKey = issue.fields.parent.key
} else {
def fields = issue.fields as Map
parentKey = fields[parentIssueName]
}
if (parentKey != 0) {
// The rest call to transition the issue
def result = post("/rest/api/2/issue/${parentKey}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: transitionID]])
.asObject(Map)
// Check if the issue was transitioned correctly
// Log out the issues updated or which failed to update
if (result.status == 204) {
logger.info("The ${parentKey} issue was also transitioned by the post function.")
// for an Epic, also transition the weekly progress status, if needed
def parentResult = get('/rest/api/2/issue/' + parentKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (parentResult.status == 200 && ((Map) parentResult.body.fields.issuetype)?.name != 'Epic') {
logger.info("Parent is not an Epic, returning")
return
}
// Specify the name of the select list field to set
def progressStatusFieldName = 'Weekly Progress Status'
// Get the Custom field to get the option value from
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == progressStatusFieldName
} as Map
// Check if the custom field returns a valid field and is not null
assert customField != null : "Cannot find custom field with name of: ${progressStatusFieldName}"
def progValue = (parentResult.body.fields[customField.id] as Map)?.value
if (progValue != "Not Started") {
logger.info("Progress status is ${progValue}, returning")
return
}
def progResult = put("/rest/api/2/issue/${parentKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
(customField.id):[value: "On Target"] as Map
]
])
.asString()
if (progResult.status == 204) {
logger.info( "The ${customField.name} select list field was successfully updated on the ${parentKey} issue")
} else {
logger.info( "${progResult.status}: ${progResult.body}")
}
} else {
logger.warn("The post function failed to transition the ${parentKey}issue. ${result.status}: ${result.body}")
}
}
error: No such property: issue for class: Script1 on line 6
Top comments (0)