Data Dump.

Purpose

Hosting

Compatible Tools

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

  • If used in a transition:

    • Comment line 2

    • Uncomment line 4

    • Change formName in line 6 to the name of the form that has all fields used in the script.

    • Change/Add in fieldNames in line 7 the name/label of all fields you want values from, separated by comma, between quotation marks.

    • Change noValue in line 8 to the message you want to show when no value is found on a field.

    • If you want to add values in the end of the issue description instead of overriding it, comment line 122 and uncomment line 123.

  • If used in the script console:

    • Change the issue key in line 2 to the key of the issue you want to sum the field values in a form.

    • Change formName in line 6 to the name of the form that has all fields used in the scripts

    • Change/Add in fieldNames in line 7 the name/label of all fields you want values from, separated by comma, between quotation marks.

    • Change noValue in line 8 to the message you want to show when no value is found on a field.

    • If you want to add values in the end of the issue description instead of overriding it, comment line 122 and uncomment line 123.

Possible use cases

  • Copying data from multiple ProForma fields into a single Jira fields makes the data searchable in JQL queries and Jira reports.

  • Summarize key data points collected in long, complex forms.

Limitations

  • All fields that will be included must be on the same form, and the same issue.

  • If one of the fields being collected has no value, then that field will be shown as “No value” in the Description field.

  • The script can be used to override or amend to, existing values in the Description field.

  • If there are multiple copies of the same form on the issue, the script will run for each copy of the form.

  • This script may 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.