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,299,230
Community Members
 
Community Events
165
Community Groups

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

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

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);


 

@Milan Ardeshana 

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

389 views 0 7
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