Snippets

Adaptavist Pre-fil labels on sub-task based on checkbox selected value

Created by Bobby Bailey
/*
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party."
*/

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.LABELS
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

@BaseScript FieldBehaviours fieldBehaviours

def issueManager = ComponentAccessor.getIssueManager()
def parent = getFieldById("parentIssueId")
def parentIssueId = parent.getFormValue() as Long
def parentIssue = issueManager.getIssueObject(parentIssueId)
def parentType = parentIssue.getIssueType()
def checkbox = parentIssue.getCustomFieldValue("Custom Field Checkbox") as List<LazyLoadedOption>

def checkBoxValues = checkbox*.value

if(getActionName() in ["Create Issue", "Create"]){
    log.error('test1')
    if("A" in checkBoxValues && parentType.name in ["Story", "Bug"]){
        log.error('test2')
        getFieldById(LABELS).setFormValue(['label_1', 'label_2'])
    }    
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.