Trying to hide the "Create Subtask" UI element based on a Single Select Custom Field value (CMR Type equals Normal"). I have tried using Script Runner UI Fragments > Hide system or plugin UI element but it is not working as expected.
Am I missing something in this script? The "Create Sub-task" disappeared completely irrespective of any value in CMR Type field.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issuedef issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id)def customFieldManager = ComponentAccessor.getCustomFieldManager()def customField = customFieldManager.getCustomFieldObjectByName("CMR Type")if (customField) {def customFieldValue = issue.getCustomFieldValue(customField)log.debug("Custom Field Value: ${customFieldValue}")return customFieldValue == 'Normal'} else {log.warn("Custom field not found: Your Custom Field Name")return false}
What is the custom field type?
Just checking because == would only work for text fields and their derivates, but not like labels or options and stuff like that.
Hi @Radek Dostál - The custom field "CMR Type" type is a single select option. No wonder why this is not working, due to this limitation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Due to what limitation? You're checking reference equality between a LazyLoadedOption class and a string.
return "Normal" == customFieldValue?.getValue()
return "Normal".equals(customFieldValue?.getValue())
Either one is fine, you just need to compare string with string.
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.
Hi @VVC Please try the script below.
customFieldValue
is not equal to 'Normal'.import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("CMR Type")
if (customField) {
def customFieldValue = issue.getCustomFieldValue(customField)
log.debug("Custom Field Value: ${customFieldValue}")
return customFieldValue != 'Normal' // Return true to show the UI element when it's NOT 'Normal'
} else {
log.warn("Custom field not found: Your Custom Field Name")
return true // Default to showing the UI element if the custom field is not found
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manoj Gangwar - Create Subtask menu item option wouldn't display even after changing the "CMR Type" custom field to any value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.