Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,552,425
Community Members
 
Community Events
184
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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 29, 2021

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
AUG Leaders

Atlassian Community Events