Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,843
Community Members
 
Community Events
168
Community Groups

How can we set the Labels system field as ReadOnly in behaviour initializer script

How can we set the Labels system field as ReadOnly in behaviour initializer provided by script runner

1 answer

0 votes

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

It is also not working for custom fields

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events