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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

🍂📹 Apptoberfest demo contest roundup: vote for your favorite demos!

Hi Community! The submissions are in (and listed below) for the 🍻🍂Apptoberfest🍂🍻 Demo Competition and it’s time for you to place your votes for the best: Analytics & reporting app demo ...

102 views 2 11
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