def issueKeyOrigin = 'ISSUE-1'
//// When using this script in the script console uncomment the next line:
def issueKeyDestination = 'ISSUE-2'
//// When using this script in a transition uncomment the next line:
//def issueKeyDestination = issue.key
def proformaPropertyKeys = []
def allIssueProperties = get('/rest/api/3/issue/' + issueKeyOrigin + '/properties/')
.header('Content-Type', 'application/json')
.asObject(Map)
if (allIssueProperties.status == 200){
for(def property : allIssueProperties.body.keys){
if(property.key.contains("proforma")){
proformaPropertyKeys.add(property.key)
}
}
}
def issueDestinationProperties = get('/rest/api/3/issue/' + issueKeyDestination + '/properties/')
.header('Content-Type', 'application/json')
.asObject(Map)
if(!issueDestinationProperties.body.keys.toString().contains("proforma.forms.i")){
if(!proformaPropertyKeys.isEmpty()){
for(def key : proformaPropertyKeys){
def property = get('/rest/api/3/issue/' + issueKeyOrigin + '/properties/' + key)
.header('Content-Type', 'application/json')
.asObject(Map)
if(property.status == 200){
if(property.body.key.contains("proforma.forms.i")){
property.body.value.state.answers.clear()
property.body.value.state.status = "o"
} else if(property.body.key.equals("proforma.forms")){
for(def form : property.body.value.forms){
form.remove("submitted")
form.remove("lock")
}
} else if(property.body.key.equals("proforma.forms.search")){
def openForms = property.body.value.count.open.value
def submittedForms = property.body.value.count.submitted.value
def lockedForms = property.body.value.count.locked.value
property.body.value.count.open = openForms + submittedForms + lockedForms
property.body.value.count.locked = 0
property.body.value.count.submitted = 0
}
def result = put('/rest/api/3/issue/' + issueKeyDestination + '/properties/' + property.body.key)
.header('Content-Type', 'application/json')
.body(property.body.value)
.asString()
}
}
}
} |