Purpose | Hosting | Compatible Tools |
---|---|---|
Change the Internal/External setting of a form | Server or Data Center | Any scripting tool, such as JMWE, Power Scripts or Scriptrunner, that uses Groovy. |
Script | import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.bc.issue.properties.IssuePropertyService import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.entity.property.EntityPropertyService Issue issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-1") String formName = "Form Name" ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() IssuePropertyService issuePropertyService = ComponentAccessor.getComponentOfType(IssuePropertyService.class) IssueManager issueManager = ComponentAccessor.getIssueManager() Closure<Long> getFormId = { def property, String name -> def slurper = new groovy.json.JsonSlurper() def parsedJson = slurper.parseText(property.value) String id parsedJson.forms.each(){ form -> if(form.name.equals(name)){ id = form.id.toString() return } } if(id){ return Long.valueOf(id) } } def allProperties = issuePropertyService.getProperties(loggedInUser, issue.id) def formId for(def property : allProperties){ if(property.key.equals("proforma.forms")){ formId = getFormId(property, formName) } } boolean changeSecondForm = false for(def property : allProperties){ if(property.key.equals("proforma.forms")){ String toReplace for(def section : property.value.split("\"id\":")){ if(section.startsWith(formId.toString())){ toReplace = section } } if(toReplace){ String replacement if(toReplace.contains("\"internal\":true")){ replacement = toReplace.replace("\"internal\":true", "\"internal\":false") } else if (toReplace.contains("\"internal\":false")){ replacement = toReplace.replace("\"internal\":false", "\"internal\":true") } EntityPropertyService.SetPropertyValidationResult validationResult = issuePropertyService.validateSetProperty( loggedInUser, issue.id, new EntityPropertyService.PropertyInput(property.value.replace(toReplace, replacement), property.key)) if(validationResult.isValid()){ issuePropertyService.setProperty(loggedInUser, validationResult) changeSecondForm = true } } } } if(changeSecondForm){ for(def property : allProperties){ if(property.key.equals("proforma.forms" + ".i" + formId)){ if(property.value.contains("\"visibility\":\"i\"")){ EntityPropertyService.SetPropertyValidationResult validationResult = issuePropertyService.validateSetProperty( loggedInUser, issue.id, new EntityPropertyService.PropertyInput(property.value.replace("\"visibility\":\"i\"", "\"visibility\":\"e\""), property.key)) if(validationResult.isValid()){ issuePropertyService.setProperty(loggedInUser, validationResult) } } else if(property.value.contains("\"visibility\":\"e\"")){ EntityPropertyService.SetPropertyValidationResult validationResult = issuePropertyService.validateSetProperty( loggedInUser, issue.id, new EntityPropertyService.PropertyInput(property.value.replace("\"visibility\":\"e\"", "\"visibility\":\"i\""), property.key)) if(validationResult.isValid()){ issuePropertyService.setProperty(loggedInUser, validationResult) } } } } } |
Installation instructions |
|
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 |
|