Hi - I am using Adaptavist for Jira.
On behaviors tab, In my listener, I have a situation where I want to make ''Fix Version/s" field read-only only for the given issue based on certain situation. I tried various things but can't seem to find any solution to it.
Any pointer would be appreciated.
Finally got it working.
I was trying to use Listener but in reality the script should be written on Behavior tab of 'Adaptavist for Jira'.
For others, this is how my script looks like.
import java.lang.Double
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import org.apache.log4j.Level
@BaseScript FieldBehaviours fieldBehaviours
log.setLevel(Level.DEBUG)
final targetCustomFieldName = 'My Custom Field Name'
def customFieldManager = ComponentAccessor.customFieldManager
def issueKey = underlyingIssue.key
log.info("From Behaviour - issueKey=="+issueKey)
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)
def targetCustomField = customFieldManager.getCustomFieldObjects(issue).find {it.getFieldName() == targetCustomFieldName && it.getCustomFieldType().getName() == "Number Field"}
log.info("Found targetCustomField to be updated as $targetCustomField");
def targetFieldValue = issue.getCustomFieldValue(targetCustomField) as Double ?: 0
log.info("From Behaviour - targetFieldValue="+targetFieldValue)
def otherCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.getFieldName() == "My Other Custom Field"}
log.info("From Behaviour - otherCustomField="+otherCustomField)
def otherCustomFieldValue = issue.getCustomFieldValue(otherCustomField)
log.info("From Behaviour - otherCustomFieldValue="+otherCustomFieldValue)
if (targetFieldValue >= getOtherCustomFieldValue(otherCustomFieldValue)) {
getFieldById(IssueFieldConstants.FIX_FOR_VERSIONS).setReadOnly(true)
log.info("From Behaviour, FIX_FOR_VERSIONS is non-editable")
} else {
getFieldById(IssueFieldConstants.FIX_FOR_VERSIONS).setReadOnly(false)
log.info("From Behaviour, FIX_FOR_VERSIONS is editable")
}
private Integer getOtherCustomFieldValue(otherCustomFieldValue) {
return 10 // OR whatever
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a custom field counter that I increment every time a change is made in 'Fix Versions/s' field. However, if that counter has reached a threshold then I want to make 'Fix Version/s' read-only/disabled only for that Issue.
'Fix Version/s' seems to be system field. If I try to grab it using code like below but getting exception.
import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
final String fieldName = "Fix Version"
getFieldByName(fieldName).setReadOnly(true)
java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:
I also tried this code which executes successfully but never makes the Fix Version read-only.
def fixVersionsField = getFieldById("fixVersions")
log.info("fixVersionsField="+fixVersionsField)
fixVersionsField.setReadOnly(true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.