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

Jordan Klein December 6, 2017

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

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2017

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.

Jordan Klein December 12, 2017

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)
0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 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

Jordan Klein December 7, 2017

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?

Jordan Klein December 7, 2017

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

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2017

Add as the first line of your script

import com.atlassian.jira.component.ComponentAccessor

Jordan Klein December 13, 2017

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) 

Suggest an answer

Log in or Sign up to answer