Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Purpose

Hosting

Compatible Tools

Unlock a form which has been set to Lock when submitted

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.Issue
import com.atlassian.jira.bc.issue.properties.IssuePropertyService
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.thinktilt.proforma.api.ApiUser
import com.thinktilt.proforma.api.FormApi

@WithPlugin("com.thinktilt.proforma.add-on")
@PluginModule
ApiUser apiUser


@WithPlugin("com.thinktilt.proforma.add-on")
@PluginModule
FormApi formApi

////If used in a transition, comment next line:
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-1")
String formName = "Form Name"
ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
IssuePropertyService issuePropertyService = ComponentAccessor.getComponentOfType(IssuePropertyService.class)

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) && form.lock){
            id = form.id.toString()
            return
        }
    }
    if(id){
        return Long.valueOf(id)
    }
}

def allProperties = issuePropertyService.getProperties(loggedInUser, issue.id)
for(def property : allProperties){
    if(property.key.equals("proforma.forms")){
        Long unlockFormId = getFormId(property, formName)
        if(unlockFormId){
            def form = formApi.unlockForm(apiUser.getCurrentUser(), issue.key, unlockFormId)
        }
    }
}

Installation instructions

  • If used in a transition:

    • Comment line 20

    • Change formName in line 21 to the name of the form that you want to unlock.

  • If used in the script console:

    • Change the issue key in line 20 to the key of the issue that has the form you want to unlock.

    • Change formName in line 21 to the name of the form that you want to unlock.

Possible use cases

Use this script to unlock a form when it reaches a given status, for example if an Approver needs to add or amend information on the form.

Limitations

  • This scripts uses a ProForma Server API, so it must be used in a version that has access to the API.

  • Only one form with the specified name will be unlocked at a time.

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

  • No labels