Purpose | Hosting | Compatible Tools |
---|---|---|
Dump data from multiple ProForma fields into the Jira Description field. | 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" def fieldNames = ["Field One", "Field Two", "Field Three", "Field Four"] String noValue = "No value" Closure<String> getIssueDescription = { String key -> def issueMap = get('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .asObject(Map) return issueMap.body.fields.description.toString() } 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 } Closure<String> getFieldId = { def property, String fieldName -> for (def question : property.value.design.questions){ if(fieldName.equals(question.value.label)){ return question.key } } } Closure getChoiceValue = { def property, String fieldName, String choiceId -> def fieldId = getFieldId(property, fieldName) for (def question : property.value.design.questions){ if(question.key.equals(fieldId)){ for(def choice : question.value.choices){ if(choice.id == choiceId){ return choice.label } } } } } Closure<String> getFieldValue = { def property, String fieldName -> for (def answer : property.value.state.answers){ String fieldId = getFieldId(property, fieldName) if(answer.key.equals(fieldId)){ if(answer.value.text && !answer.value.text.equals("")){ return answer.value.text } else if(answer.value.choices){ String choiceValues = "" for(def choice : answer.value.choices){ if(choiceValues.equals("")){ choiceValues = getChoiceValue(property, fieldName, choice) } else { choiceValues = choiceValues + ", " + getChoiceValue(property, fieldName, choice) } } return choiceValues.equals("") ? noValue : choiceValues } else if(answer.value.users){ String userValues = "" for(def user : answer.value.users){ if(userValues.equals("")){ userValues = user.name } else { userValues = userValues + ", " + user.name } } return userValues.equals("") ? noValue : userValues } else if(answer.value.date || answer.value.time){ String dateTime = "" if(answer.value.date){ dateTime = dateTime + answer.value.date } if(answer.value.time){ if(answer.value.date){ dateTime = dateTime + " " + answer.value.time } else { dateTime = dateTime + answer.value.time } } return dateTime.equals("") ? noValue : dateTime } } } return noValue } 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) String result = "" for(def formId : forms){ def property = get('/rest/api/3/issue/' + issueKey + '/properties/proforma.forms.i' + formId) .header('Content-Type', 'application/json') .asObject(Map) if(property.status == 200){ if(property.body.value.schemaVersion.equals(8)){ for(def fieldName : fieldNames) { if(result.equals("")){ result = getFieldValue(property.body, fieldName) } else { result = result + ", " + getFieldValue(property.body, fieldName).toString() } } } } } if(!result.equals("")){ def issueUpdate = put("/rest/api/2/issue/${issueKey}") .header('Content-Type', 'application/json') .body([ fields: [ description: result //description: getIssueDescription(issueKey) + " " + result ] ]) .asString() } } |
Installation instructions |
|
Possible use cases |
|
Limitations |
|