How do I reference checkbox and drop-down list custom fields in a Script Listener condition?

I'm trying to use the "Send a Custom Email" option under Script Listeners with the Scriptrunner add-on.

 

Particularly, I want to send an email when the following 4 conditions are met:

  • IssueType = Game Bug
  • Status = Reviewing
  • Custom Field Level = whitebox_01 (single-select dropdown field)
  • Custom Field Game Mode = RB (multi-select checkbox field)

 

Right now, I have the email set to fire on an Issue Updated event with the following Condition & Configuration:

 

(issue.issueType.name == 'Game Bug') && (cfValues['Game Mode'] == 'RB') && (cfValues('Level') == 'whitebox_01' && (issue.getStatusObject.getName() == 'Reviewing')

 

I believe some of my syntax is off on the condition, particularly referencing the custom field names correctly.

 

2 answers

This widget could not be displayed.
Alexey Matveev Community Champion Dec 06, 2017

You can check checkbox and multi select like this

ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Game Mode").getValue(issue).findAll{it.toString().equals("RB")}.size() > 0

ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Level").getValue(issue).findAll{it.toString().equals("whitebox_01")}.size() > 0

Thanks for the response.

Using those conditions by themselves is giving me the following error:

[Static type checking] - The variable [ComponentAccessor] is undeclared.

How do I declare the ComponentAccessor as a variable in a Condition/Configuration?

cfValues['Game Mode']*.value.contains('RB') also isn't working

Alexey Matveev Community Champion Dec 12, 2017

Add as the first line of your script

import com.atlassian.jira.component.ComponentAccessor

With the added import line, I still get this log and no email sent:

 

2017-12-13 10:21:40,528 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-12-13 10:21:40,528 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ST-136280, actionId: 281, file: null
groovy.lang.MissingPropertyException: No such property: summary for class: groovy.lang.Binding
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMail(SendCustomEmail.groovy:485)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMail$1.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMailWithConditionResult(SendCustomEmail.groovy:465)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMailWithConditionResult$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMailWithConditionResult$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.doScript(SendCustomEmail.groovy:561) 
This widget could not be displayed.

You can use the following condition which should work for your case:

issue.issueType.name == 'Game Bug' &&
issue.status.name == "Reviewing" &&
cfValues['Level']?.value == 'whitebox_01' &&
cfValues['Game Mode']*.value.contains('RB')

Hope this helps.

Thanks for the reply. Can't get the 'Game Mode' condition to execute properly. It returns a log with this error:

2017-12-12 10:06:47,187 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-12-12 10:06:47,187 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SP-135891, actionId: 281, file: null
groovy.lang.MissingPropertyException: No such property: summary for class: groovy.lang.Binding
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMail(SendCustomEmail.groovy:485)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMail$1.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.constructMailWithConditionResult(SendCustomEmail.groovy:465)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMailWithConditionResult$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$constructMailWithConditionResult$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.doScript(SendCustomEmail.groovy:561)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 2 hours ago in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

11 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you