Dynamic (Checklist for jira) items based on drop-down value selection (Listen using behaviours)

Deleted user October 1, 2019

Hi All.

I am on jira server, using Scriptrunner-behaviours and checklist for jira addon on my environment.

We need dynamic checklist which means checklist items changes based drop-down value selection. 
single select drop-down field selectchecklist has two values a and 1.

I have create check list field checklistA and deleted options from it to make it empty.

when a is selected checklistA should have three checkitems a, b and c and when 1 is selected checklistA should have three checkitems 1,2 and 3.

I have created following script but I am not sure how to set the value in behaviours.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf = customFieldManager.getCustomFieldObjectByName("checklist_a");
def cfConfig = cf.getRelevantConfig(underlyingIssue)
def cfType = cf.getCustomFieldType()

def listSelectChecklist = (String) getFieldById("customfield_13202").value
def checklistA = getFieldById("customfield_13200")
def desc = getFieldById("description")
log.warn("Outside condition")
if (listSelectChecklist == "1") {
log.warn("inside selection")
def item1 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item 1", "checked" : true, "mandatory" : false}')
def item2 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item 2", "checked" : true, "mandatory" : false}')
def allItems = new ArrayList<Object>();
allItems.add(item1);
allItems.add(item2);
checklistA.setFieldOptions(allItems)
}else if (listSelectChecklist == "a") {
def item1 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item a", "checked" : true, "mandatory" : false}')
def item2 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item b", "checked" : true, "mandatory" : false}')
def allItems = new ArrayList<Object>();
allItems.add(item1);
allItems.add(item2);
checklistA.setFieldOptions(allItems)}

 Following is the behaviours setting capture:script-1.PNG

1 answer

1 accepted

0 votes
Answer accepted
Deleted user October 1, 2019

This is achieved using script listener rather than behaviours. I have used Issue created and updated events for my project for following filter.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CustomField listSelectChecklist = customFieldManager.getCustomFieldObject("customfield_13202")
def CustomField checkListField = customFieldManager.getCustomFieldObject("customfield_13200")
def cfType = checkListField.getCustomFieldType()
def listSelectChecklistValue = (String) issue.getCustomFieldValue(listSelectChecklist)
log.warn("Outside condition list selction value = " +listSelectChecklistValue )
if (listSelectChecklistValue == "1") {
log.warn("inside selection")
def item1 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item 1", "checked" : false, "mandatory" : false}')
def item2 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item 2", "checked" : false, "mandatory" : false}')
def allItems = new ArrayList<Object>();
allItems.add(item1);
allItems.add(item2);
issue.setCustomFieldValue(checkListField,allItems)
}else if (listSelectChecklistValue == "a") {
def item1 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item a", "checked" : false, "mandatory" : false}')
def item2 = cfType.getSingularObjectFromString('{"name" : "My Checklist Item b", "checked" : false, "mandatory" : false}')
def allItems = new ArrayList<Object>();
allItems.add(item1);
allItems.add(item2);
issue.setCustomFieldValue(checkListField,allItems)
}
ComponentAccessor.issueManager.updateIssue(currentUser, issue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false);


 
Dilan Kaplan December 4, 2020

@[deleted] 

Is there a way to achieve the same outcome without having to code it? 

Deleted user December 4, 2020

you can reach out to checklist support and provide them detailed information and they can help you out. the guys are really awesome.

Like Dilan Kaplan likes this
Dilan Kaplan December 7, 2020

Thank-you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events