Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Purpose

Hosting

Compatible Tools

Unlock a form which has been set to Lock when submitted

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("l")){
                    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 lockedForms = formProperty.value.count.locked.value
                    formProperty.value.count.open = openForms + 1
                    formProperty.value.count.locked = lockedForms - 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")
                            form.remove("lock")
                            def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + formProperty.key)
                                              .header('Content-Type', 'application/json')
                                              .body(formProperty.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 unlock.

  • 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 unlock.

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

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

  • 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.

  • No labels