Add a Form Template to an Issue(s)
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 | 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 |
|
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 |
|