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

Create Sub-Task Automatically when checkbox field values are checked

Mahesh Kallepalli December 26, 2019

Hello ,

We are having a checkbox custom field while creating a ticket when checkboxes are checked automatically a subtask has to be created. Please find below the code that I have implemented in the listener. Can anyone review my code and suggest to me on the right track.

 

def createSubtask = false
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def chkBxFld = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10563');
def selectedOption = issue.getCustomFieldValue(chkBxFld)
log.warn('selectedOption'+selectedOption.toString())
//def myFieldList = ["Decision Pro","Laser Pro","Credit Quest","Kroll"];
//for(option in myFieldList){
if(selectedOption=='Kroll'|| selectedOption=='Laser Pro'|| selectedOption=='Credit Quest'|| selectedOption=='Decision Pro'){
createSubtask = true
}
//}
return createSubtask

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 26, 2019

The options selected are not strings, they are option objects.  If you want to work with just the option's name (as it appears to your humans), you should use .getValue() to get the name out of the option.

Mahesh Kallepalli December 26, 2019

Hi @Nic Brough -Adaptavist- 

 

Thanks for your response..!!

def chkBxFld = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10563');

we are getting null pointer exception on null object , Can you guide me on right track with my code as i'm new to scripting.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 27, 2019

Try

def customFieldName = "Name of your custom field"

def chkBxFld = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"

Like Mahesh Kallepalli likes this
TAGS
AUG Leaders

Atlassian Community Events