/
Unlock a Form.
Unlock a Form.
Purpose | Hosting | Compatible Tools |
---|---|---|
Unlock and reopen a locked form. | Cloud | Any scripting tool, such as JMWE, Power Scripts or Scriptrunner, that uses Groovy. |
Script | //// When using this script in the script console uncomment the next line:
def issueKey = 'ISSUE-1'
//// When using this script in a transition uncomment the next line:
// def issueKey = issue.key
String formName = "Form Name"
Closure getFormIds = { def propertyValue, String name ->
def ids = []
for(def form : propertyValue.value.forms){
if(form.name.equals(name)){
ids.add(form.id)
}
}
return ids
}
def proFormaForm = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms')
.header('Content-Type', 'application/json')
.asObject(Map)
if(proFormaForm.status == 200){
def forms = getFormIds(proFormaForm.body, formName)
for(def formId : forms){
def property = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms.i' + formId)
.header('Content-Type', 'application/json')
.asObject(Map)
boolean updateAllForms = false
if(property.status == 200){
if(property.body.value.schemaVersion.equals(8)){
if(property.body.value.state.status.equals("l")){
property.body.value.state.status = "o"
def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + property.body.key)
.header('Content-Type', 'application/json')
.body(property.body.value)
.asString()
updateAllForms = true
}
}
}
if(updateAllForms){
def searchProperty = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms.search')
.header('Content-Type', 'application/json')
.asObject(Map)
if(searchProperty.status == 200){
def openForms = searchProperty.body.value.count.open.value
def lockedForms = searchProperty.body.value.count.locked.value
searchProperty.body.value.count.open = openForms + 1
searchProperty.body.value.count.locked = lockedForms - 1
def insertSearchProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + searchProperty.body.key)
.header('Content-Type', 'application/json')
.body(searchProperty.body.value)
.asString()
}
for(def form : proFormaForm.body.value.forms){
if(form.id == formId){
form.remove("submitted")
form.remove("lock")
def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + proFormaForm.body.key)
.header('Content-Type', 'application/json')
.body(proFormaForm.body.value)
.asString()
}
}
}
}
} |
Installation instructions |
|
Possible use cases | Use this script to unlock a form when it reaches a given status, for example if an Approver needs to add or amend information on the form. |
Limitations |
|