Purpose | Hosting | Compatible Tools |
---|---|---|
Reopen a submitted 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 getFormId = { def allProperties, String name -> for(def formProperty : allProperties){ if(formProperty.key.equals("proforma.forms")){ for(def p : formProperty.value.forms) { if(p.name.equals(name)){ return p.id } } } } } def proformaPropertyKeys = [] def allIssueProperties = get('/rest/api/3/issue/' + issueKey + '/properties/') .header('Content-Type', 'application/json') .asObject(Map) if (allIssueProperties.status == 200){ for(def property : allIssueProperties.body.keys){ if(property.key.contains("proforma.forms")){ proformaPropertyKeys.add(property.key) } } } def formProperties = [] if(!proformaPropertyKeys.isEmpty()){ for(def key : proformaPropertyKeys){ def property = get('/rest/api/3/issue/' + issueKey + '/properties/' + key) .header('Content-Type', 'application/json') .asObject(Map) if(property.status == 200){ formProperties.add(property.body) } } } def formId if(!formProperties.isEmpty()){ formId = getFormId(formProperties, formName) if(formId){ boolean updateAllForms = false for(def formProperty : formProperties){ if(formProperty.key.equals("proforma.forms" + ".i" + formId) && formProperty.value.schemaVersion.equals(8)){ if(formProperty.value.state.status.equals("s")){ formProperty.value.state.status = "o" def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + formProperty.key) .header('Content-Type', 'application/json') .body(formProperty.value) .asString() updateAllForms = true } } } if(updateAllForms){ for(def formProperty : formProperties){ if(formProperty.key.equals("proforma.forms.search")){ def openForms = formProperty.value.count.open.value def submittedForms = formProperty.value.count.submitted.value formProperty.value.count.open = openForms + 1 formProperty.value.count.submitted = submittedForms - 1 def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + formProperty.key) .header('Content-Type', 'application/json') .body(formProperty.value) .asString() } else if(formProperty.key.equals("proforma.forms")){ for(def form : formProperty.value.forms){ if(form.id == formId){ form.remove("submitted") def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + formProperty.key) .header('Content-Type', 'application/json') .body(formProperty.value) .asString() } } } } } } } |
Installation instructions |
|
Possible use cases | Use this script to reopen a submitted form, for example if a form needs to be reopened for an Approver to add/amend information. |
Limitations |
|