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

Listener that checks Checkbox when Custom field is edited.

Hello,

 

like the title suggests, i need a listener that checks a Checkbox if certain custom fields have been edited. Anybody knows something similar that i can use or has some suggestions?  

 

Thank you in advance

2 answers

Hi @SG1337 ,

You can add this script in a Issue Updated listener : 

import com.atlassian.jira.component.ComponentAccessor 
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def customFieldChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Name of your custom field"}

if (customFieldChanged){
def optionsManager = ComponentAccessor.optionsManager

int checkBoxFieldId = 13000
def checkBoxField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(checkBoxFieldId)
def checkboxFieldConfig = checkBoxField.getRelevantConfig(issue)
def options = optionsManager.getOptions(checkboxFieldConfig)
def optionsToSet = options.findAll { it.value in ["option1_to_check", "option2_to_check"] }
def checkBoxFieldValue = issue.getCustomFieldValue(checkBoxField)

checkBoxField.updateValue(null, issue, new ModifiedValue(checkBoxFieldValue, optionsToSet), new DefaultIssueChangeHolder())
}

Antoine

Thx for your answer, i tried it but it shows an error in last line, when i try to execute it it gives me this error

 

 

 

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-09-06 09:44:51,907 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-09-06 09:44:51,908 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script383.groovy: 17: expecting '}', found '' @ line 17, column 125.
   w DefaultIssueChangeHolder()) 
                                 ^
1 error

ok i found the mistake, its just a } at the end, but it still doesnt check my Box. I replaced 

"Name of your custom field"

with my custom field name that should be checked for changes

 

I replaced this ID with the ID of my checkbox field

int checkBoxFieldId = 13000

 

And i replaced this with the option of my Custom Field that should be checked like this

it.value in ["My_Option"]

 

What am i doing wrong?

Antoine Berry Community Leader Sep 06, 2019

You should check the logs to see if the code fails, and if it correctly enters the if condition when you edit the field.

Antoine Berry Community Leader Sep 11, 2019

Hi @SG1337 ,

Were you able to make this work ?

I see you are trying to use scriptrunner to achieve this. But I think automation for JIRA might be your best bet and is easy to configure. Both plugins offer customfield changed event in their listeners but Automation for JIRA offers the ability to capture specific field easily. You can then update the checkbox field as you see fit using the rule.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

363 views 1 3
Join discussion

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