How To set Original Estimate Field read only based on certain conditions

Likhita March 5, 2025

Hi All,

I am trying to set the "Original Estimate" field as read-only based on the issue type and a specific user group. I can correctly determine whether the logged-in user belongs to the group, but the field is not becoming read-only as expected. Is there any other possible solution to achieve this?

This is the code I have used in Script runner behaviours

<<

import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours fieldBehaviours
def issueManager = ComponentAccessor.getIssueManager()
def groupManager = ComponentAccessor.getGroupManager()
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Define the user group allowed to edit
def allowedGroup = "DEV-Delivery Manager"

def parent = getFieldById("parentIssueId")
def parentIssueId = parent.getFormValue() as Long
def parentIssue = issueManager.getIssueObject(parentIssueId)

def parentType = parentIssue.issueType.name as String
log.info("parentType"+parentType)
def originalEstimateField = getFieldByName('Original Estimate')

if(parentType == "Client Defect")
{
    log.info("Client defect issue type")
    // Check if the logged-in user is in the allowed group
    def isUserAllowed = groupManager.getGroupsForUser(loggedInUser)?.any { it.name == allowedGroup }
    log.info("name" + isUserAllowed)

    if (isUserAllowed) {
        log.info("User allowed to edit CD - Original estimate")
        originalEstimateField.setReadOnly(false)
    } else {
        log.info("User not allowed to edit CD - Original estimate ")
        originalEstimateField.setReadOnly(true)
    }
}
else
{
 log.info("Different issue type")
 originalEstimateField.setReadOnly(false)  
}
>>

0 answers

Suggest an answer

Log in or Sign up to answer