Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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)  
}
>>

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 12, 2025

Hi @Likhita

Please clarify: Is the Original Estimate field a custom field or a default field that is already available?

Please also clarify: Are you able to view the Original Estimation on the Create / Edit / Assign or Transition screen? If yes, then the Server-Side Behaviour can be configured for it. Otherwise, the Behaviour will not work for it.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

 

Suggest an answer

Log in or Sign up to answer