Change the Internal/External Setting.

Purpose

Hosting

Compatible Tools

Purpose

Hosting

Compatible Tools

Change the Internal/External setting of a form.

Cloud

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

Script

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 //// 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) boolean updateSecondForm = false for(def formProperty : formProperties){ if(formProperty.key.equals("proforma.forms" + ".i" + formId) && formProperty.value.schemaVersion.equals(8)){ if(formProperty.value.state.visibility == "i"){ formProperty.value.state.visibility = "e" } else if(formProperty.value.state.visibility == "e"){ formProperty.value.state.visibility = "i" } def insertProperty = put('/rest/api/3/issue/' + issueKey + '/properties/' + formProperty.key) .header('Content-Type', 'application/json') .body(formProperty.value) .asString() updateSecondForm = true } } if(updateSecondForm){ for(def formProperty : formProperties){ if(formProperty.key.equals("proforma.forms")){ for(def form : formProperty.value.forms){ if(form.id.equals(formId)){ if(form.internal == true){ form.internal = false } else if(form.internal == false){ form.internal = true } 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 move between internal/external statuses.

  • If used in the script console:

    • Change issue key in line 2 to the issue that has the form you want to move between internal/external statuses.

    • Change formName in line 6 to the name of the form that you want to move between internal/external statuses.

Possible use cases

Use this script to change a form from internal to external or vise versa. For example, you can have a form which was submitted on the portal become Internal (not visible on the portal) when it reaches a given status.

Limitations

  • If multiple forms with the same name exist on the issue, the script will only change the first setting on the first form.