Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

...

Code Block
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.

...

No script is available. However, ProForma offers anAPI for unlocking a form.