Reopen a Form.

Purpose

Hosting

Compatible Tools

Purpose

Hosting

Compatible Tools

Reopen a submitted form.

Cloud

Any scripting tool, such as JMWE, Power Scripts or Scriptrunner, that uses Groovy.

Script

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 //// 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("s")){ 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 submittedForms = searchProperty.body.value.count.submitted.value searchProperty.body.value.count.open = openForms + 1 searchProperty.body.value.count.submitted = submittedForms - 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") def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + proFormaForm.body.key) .header('Content-Type', 'application/json') .body(proFormaForm.body.value) .asString() } } } } }

Installation instructions

  • If used in a transition:

    • Comment line 2

    • Uncomment line 4

    • Change formName in line 6 to the name of the form that you want to reopen.

  • If used in the script console:

    • Change the issue key in line 2 to the key of the issue that has the form you want to reopen.

    • Change formName in line 6 to the name of the form that you want to reopen.

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

  • All copies of the form on the issue be reopened.