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

how to define the script of the condition to be met using send a custom email script runner script

mel vega Jan 06, 2016

Hi,

i'm trying to set up a "send a custom email" script runner post function and I struggle to define the script of the condition to be met.

the condition is based on a checkboxes custom field. The field should be equal to a specific value.

I tried to select "Has string custom field value equal to " in the suggested examples but it does not work and I click Preview, the condition is set as false.

would you have any idea of the right code to write for a checkboxes custom field?

thanks in advance

melissa

2 answers

1 accepted

1 vote
Answer accepted
JamieA Jan 06, 2016

You may find it easier to use the cfValues map which is passed in:

https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_a_multi_select_option_is_selected

As Thanos said, with checkboxes it can be multiple. To check for a single specific checkbox being checked, and no others, you'd use:

cfValues['Name of field']*.value == ['An item']
mel vega Jan 06, 2016

thanks a lot to you both. It perfectly works. Just another question : is there a way to reformat the email body and configure a line break for each custom field ? many thanks for your help. it's great

JamieA Jan 07, 2016

Hi... I'm not sure what you mean. If using html use <p> markers.. If you paste more of the template that would help us answer.

mel vega Jan 07, 2016

great! i did not know the use of <p> markers ! I'm very very new in coding ! thanks a lot ot's perfect now

0 votes
Thanos Batagiannis [Adaptavist] Community Leader Jan 06, 2016

Hi Melissa

Below there is a script where you can use in order to get the checkbox values 

import com.atlassian.jira.component.ComponentAccessor
import java.util.ArrayList

def customField2 = customFieldManager.getCustomFieldObjectByName("checkbox")
ArrayList listOfCheckBoxValues = issue.getCustomFieldValue(customField2) as ArrayList
 
if (!listOfCheckBoxValues)
	return false

if (listOfCheckBoxValues*.value.contains("option1"))
	return true
else 
    return false

A note. By default you can select more than one boxes therefore you always get a list of selected values. In case you want to use radio buttons where by default you can select only one value the script will be slightly different. Please let me know if you need further assistance.

Kind regards

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

8,309 views 9 18
Read article

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