Scriptrunner Behaviours to set all fields read only instead of on the workflow status

Steve Letch September 28, 2022

Requirement:

To avoid having to set every field available on the edit screen individually to read only, it would be a lot easier to just use an initializer that sets every field to editable false depending on project role.

 

The reason I want to use Behaviors for this instead of setting editable false on the status on the workflow, is because my workflow schemes are shared and I don't want the restriction to apply to other projects and I also don't want to have to copy the project over to a clone of the same workflow just to satisfy this requirement.

 

Basically something like the below:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
 
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
 
// if the current user is in the Users role only, set the issue type to "Story", and lock it
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
 
def usersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
if (Status == Done) {
    getFieldById(>>>>>ALL FIELDS<<<<)
        .setReadOnly(true)
}

1 answer

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2022

You can get to each fields using the getFieldScreen method that's built into behaviours.

something like

getFieldScreen().tabs.each { tab ->
tab.fieldScreenLayoutItems.each { field ->
getFieldById(field).setReadOnly(true)
}
}

Or as a one-liner

fieldScreen.tabs*.fieldScreenLayoutItems*.each{getFieldById(it.fieldId).readOnly = true}
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 7, 2024

@Peter-Dave Sheehan Thank You,

I just used this to hide all fields, then show only specified fields dependant on the Customer Request Type, from another one of your posts :-)

https://community.atlassian.com/t5/Jira-Service-Management/Re-How-do-I-get-current-Customer-Request-Type-in-Behavio/qaq-p/2187461/comment-id/120003#M120003

Like Peter-Dave Sheehan likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.2
TAGS
AUG Leaders

Atlassian Community Events