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

//// 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.