How can we set the Labels system field as ReadOnly in behaviour initializer provided by script runner
In what circumstances? If you don't want people using the field, remove it from the create/edit screens or the field configuration.
Hello @Nic Brough -Adaptavist-
I want to replicate the functionality:
https://scriptrunner.adaptavist.com/4.3.4/jira/fragments/CreateConstrainedIssue.html
The create constrained issue fragment is working fine. Now there is a behaviour, I have associated with it using the id of the fragment. I want to copy values of a few fields from current to new issue and I want that the fields who are populated in the current issue should be displayed as ReadOnly when user clicks on button. Here is the script, but it is not working for Labels system field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
log.error "contextIssue--"+contextIssue
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(contextIssue.id)
log.error "labels--"+labels
def contextIssueWorkingCommentCF = customFieldManager.getCustomFieldObjectsByName('Working Comment').first()
def contextIssueWorkingCommentValue = contextIssue.getCustomFieldValue(contextIssueWorkingCommentCF) as String
log.error "workingComment--"+contextIssueWorkingCommentValue
def contextIssueNoCF = customFieldManager.getCustomFieldObjectsByName('No.').first()
def contextIssueNoValue = contextIssue.getCustomFieldValue(contextIssueNoCF)
log.error "no--"+contextIssueWorkingCommentValue
log.error "class of no cf----"+contextIssueNoValue.getClass()
if (getBehaviourContextId() == "P3_buttonToCreateBUS") {
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)
getFieldById("summary").setFormValue("${contextIssue.summary}").setReadOnly(true)
getFieldById("description").setFormValue("${contextIssue.description}").setReadOnly(true)
getFieldById("priority").setFormValue("${contextIssue.priority}").setReadOnly(true)
if ((contextIssueWorkingCommentValue) != null)
getFieldByName("Working Comment").setFormValue(contextIssueWorkingCommentValue).setReadOnly(true)
if ((contextIssueNoValue) != null)
getFieldByName("No.").setFormValue(contextIssueNoValue).setReadOnly(true)
def values = []
labels.each { values.add(it.getLabel()) }
def labelField = getFieldById("labels")
if (!labels.isEmpty())
labelField.setFormValue(values).setReadOnly(true)
}
Any help would be appreicated
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.