Versions Compared

Key

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

Purpose

Hosting

Compatible Tools

Copy form templates to an issue(s).

Form templates will be copied from a source issue to a destination issue. Regardless of the state of the forms on the source issue (open, submitted, etc.), the templates added to the target issue will be blank (no responses) and in an open state, ready for editing.

Cloud

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

Script

Code Block
def issueKeyOrigin = 'ISSUE-1'
//// When using this script in the script console uncomment the next line:
def issueKeyDestination = 'ISSUE-2'
//// When using this script in a transition uncomment the next line:
//def issueKeyDestination = issue.key

def proformaPropertyKeys = []
def allIssueProperties = get('/rest/api/3/issue/' + issueKeyOrigin + '/properties/')
        .header('Content-Type', 'application/json')
        .asObject(Map)

if (allIssueProperties.status == 200){
    for(def property : allIssueProperties.body.keys){
        if(property.key.contains("proforma")){
            proformaPropertyKeys.add(property.key)
        }
    }
}

def issueDestinationProperties = get('/rest/api/3/issue/' + issueKeyDestination + '/properties/')
        .header('Content-Type', 'application/json')
        .asObject(Map)

if(!issueDestinationProperties.body.keys.toString().contains("proforma.forms.i")){
    if(!proformaPropertyKeys.isEmpty()){
        for(def key : proformaPropertyKeys){
            def property = get('/rest/api/3/issue/' + issueKeyOrigin + '/properties/' + key)
                    .header('Content-Type', 'application/json')
                    .asObject(Map)

            if(property.status == 200){
                if(property.body.key.contains("proforma.forms.i")){
                    property.body.value.state.answers.clear()
                    property.body.value.state.status = "o"
                } else if(property.body.key.equals("proforma.forms")){
                    for(def form : property.body.value.forms){
                        form.remove("submitted")
                        form.remove("lock")
                    }
                } else if(property.body.key.equals("proforma.forms.search")){
                    def openForms = property.body.value.count.open.value
                    def submittedForms = property.body.value.count.submitted.value
                    def lockedForms = property.body.value.count.locked.value
                    property.body.value.count.open = openForms + submittedForms + lockedForms
                    property.body.value.count.locked = 0
                    property.body.value.count.submitted = 0
                }

                def result = put('/rest/api/3/issue/' + issueKeyDestination + '/properties/' + property.body.key)
                      .header('Content-Type', 'application/json')
                      .body(property.body.value)
                      .asString()
            }
        }
    }
}

Installation instructions

  • If used in a transition:

    • Change the issue key in line 1 to the key of the issue you want to take the template forms from.

    • Comment line 3 and uncomment line 5.

  • If used in the script console:

    • Change the issue key in line 1 to the key of the issue you want to take the template forms from.

    • Change the issue key in line 3 to the key of the issue you want to add the form templates to.

Possible use cases

Use this script when you want to add a form template under selected circumstances. For instance, if Change Type = Normal, then add the CAB Approval form.

Limitations

  • The script will only work if there are no forms on the destination issue. Alternatively, you can comment out lines 24 and 56 to override any existing forms on the destination issue.

  • All templates on the source issue will be copied to the destination issue, and you can modify the script to add multiple copies of the templates to the destination issue.

  • You may need to refresh the destination issue to see the forms.

  • Note that this script will not work if the form template is over 32 KB. You can limit the size of your forms by using multiple smaller forms.