Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

Hosting

Compatible Tools

Reopen a submitted form.

Cloud

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

Script

Code Block
//// 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
getFormIds = { def 
allProperties
propertyValue, String name ->
    
for(
def 
formProperty
ids 
: allProperties){
= []
    
if(formProperty.key.equals("proforma.forms")){
for(def 
p
form : 
formProperty
propertyValue.value.forms)
{
	    
if(
p
form.name.equals(name)){
	        
return p.id
ids.add(form.id)
	    }
	}
    return ids
}

} }
def 
proformaPropertyKeys
proFormaForm = 
[] def allIssueProperties =
get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms')

    .header('Content-Type', 'application/json')

    
.asObject(Map)
    
if
(
allIssueProperties
proFormaForm.status == 200){
    
for(
def
property : allIssueProperties.body.keys){
 
if(property.key.contains("proforma.
forms
")){
 
proformaPropertyKeys.add(property.key) } } } def formProperties = [] if(!proformaPropertyKeys.isEmpty()){
= getFormIds(proFormaForm.body, formName)
    for(def 
key
formId : 
proformaPropertyKeys
forms){
        def property = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms.i' + 
key
formId)
                .header('Content-Type', 'application/json')
                .asObject(Map)
        
if(property.status
boolean updateAllForms =
= 200){
 false
     
formProperties.add(property.body)
   
   
}
     
} } def formId
if(
!formProperties.isEmpty()){ formId = getFormId(formProperties, formName) if(formId){ boolean updateAllForms = false for(def formProperty : formProperties
property.status == 200){
            if(
formProperty.key.equals("proforma.forms" + ".i" + formId) && formProperty.
property.body.value.schemaVersion.equals(8)){
                if(
formProperty
property.body.value.state.status.equals("s")){
                    
formProperty
property.body.value.state.status = "o"
                    def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + 
formProperty
property.body.key)
                                      .header('Content-Type', 'application/json')
                                      .body(
formProperty
property.body.value)
                                      .asString()
                    updateAllForms = true
                }
            }
        }
        if(updateAllForms){
           
for(def formProperty : formProperties){
 def searchProperty = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms.search')
                    
if(formProperty.key.equals("proforma.forms.search")){
.header('Content-Type', 'application/json')
                    .asObject(Map)
            if(searchProperty.status == 200){
                def openForms = 
formProperty
searchProperty.body.value.count.open.value

                
def submittedForms = 
formProperty
searchProperty.body.value.count.submitted.value
                
formProperty
searchProperty.body.value.count.open = openForms + 1
                
formProperty
searchProperty.body.value.count.submitted = submittedForms - 1

                def 
insertProperty
insertSearchProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + 
formProperty
searchProperty.body.key)

                        
.header('Content-Type', 'application/json')

                        
.body(
formProperty
searchProperty.body.value)

                        
.asString()
            
}
else
 
if(formProperty.key.equals("proforma.forms")){
           
for(def form : 
formProperty
proFormaForm.body.value.forms){

                if(form.id == formId){

                    
form.remove("submitted")
                    
def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + 
formProperty
proFormaForm.body.key)

                                      .header('Content-Type', 'application/json')

                                      
.body(
formProperty
proFormaForm.body.value)
                                      
.asString()

                
}
}

            
}
        
}

    
}
} Note that this script will not work if the form is over 32 KB. You can limit the size of your forms by using multiple smaller forms, and by including character/word limits on your text fields
}

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

  • Only one form with the specified name will be reopened at a time.

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