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
Hi @GS1337 ,
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should check the logs to see if the code fails, and if it correctly enters the if condition when you edit the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.