Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

141 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you