//Copy the value of a scripted field in a "standard" jira custom field to be used anywhere
//when the issue event is launched
def scriptedFieldName = "calculate" // change by your scripted field name
def destinationCf = "number1" // change by your destination standard cf name
def returnValue = "" // store the value of the scripted field
def scriptedFieldsForIssue = get("rest/api/2/issue/${issue.key}/properties")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.keys
.findAll { it['key'].contains('scripted-field-')}['self']
if (scriptedFieldsForIssue == []) {
return "No Scripted Field value exists yet on issue ${issueKey} with the name ${scriptedFieldName}."
}
scriptedFieldsForIssue.each {
def potentialVal = get("${it}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
if (potentialVal.value.name == "${scriptedFieldName}") {
returnValue = (potentialVal.value.value) as String
}
}
// get destination custom field
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def toUpdate1CfId = customFields.find { it.name == destinationCf }?.id
def resp = put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
(toUpdate1CfId): returnValue
]
])
.asString()
assert resp.status == 204
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.