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

SWAPNIL SRIVASTAV
Contributor
December 29, 2021

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

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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.

SWAPNIL SRIVASTAV
Contributor
December 29, 2021

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

SWAPNIL SRIVASTAV
Contributor
December 29, 2021

It is also not working for custom fields

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events