Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Likhita March 5, 2025 edited

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
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events