Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use Dynamic Control when sending email in Listener

Diana
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.
July 25, 2022

I'm referencing this documentation on using Dynamic Control for sending emails, but I can't seem to get my script right.

I went on ScriptRunner > Create Listener > Send a custom email > Events set to "Issue Updated" > Condition and Configuration:

if (cfValues['Team']*.value.contains('Team A')){

mail.setTo ("john.smith@gmail.com")}

if (cfValues['Team']*.value.contains('Team B'){

mail.setTo("jane.smith@gmail.com")}

But when I select Preview, "Condition evaluated to false". It becomes true when I comment out jane.smith email. But my custom field is a single select list, and we have over 30 Teams. This email trigger doesn't need to go on a workflow since whenever a Team is updated, it can happen on any workflow status or transition. Do I need to make 30 custom listener scripts? Is there a way I can condense it to 1 script using the Dynamic Control? 

I've looked at filter subscriptions as well, but they will not work for us.

2 answers

2 accepted

0 votes
Answer accepted
Diana
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.
July 26, 2022 edited

EDIT:

I figured it out! (so simply, I feel like a fool):

if (cfValues['Team']?.value == 'Team A'){
mail.setTo("john.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team B'){
mail.setTo("jane.smith@gmail.com") }

//start a brand new if/else

if (cfValues['Team']?.value == 'Team C'){
mail.setTo("jack.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team D'){
mail.setTo("joe.smith@gmail.com") }

etc

0 votes
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 25, 2022

Hi

 

I do not use this often but first, contains('Team A') is relevant on an ArrayList, meaning for a multi-select field. So you should check what is returned when getting the value of a single select list,

 

You should use 

if (cfValues['Team']?.value == 'TeamA'){

 

 

Diana
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.
July 26, 2022

Hi @Florian Bonniec 

Condition evaluated is still false when using  value == . It only becomes true when I put only 1 email mail.setTo, yet for some reason when I add more than 1 mail.setTo, it doesn't work.

Diana
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.
July 26, 2022

I also tried this, but to no avail:

if (changeItems.any { it.get('field') == 'Team'} && cfValues['Team']?.value == 'Team A'){

mail.setTo("john.smith@gmail.com")}

if (changeItems.any { it.get('field') == 'Team'} && cfValues['Team']?.value == 'Team B'){

mail.setTo("jane.smith@gmail.com")}

 

I also tried switching to non-event issue, but I couldn't figure out either.

Diana
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.
July 26, 2022

hi @Florian Bonniec 

I figured it out! (so simply, I feel like a fool)

I needed to use "else" and not if! So for anyone searching:

if (cfValues['Team']?.value == 'Team A'){
mail.setTo("john.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team B'){
mail.setTo("jane.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team C'){
mail.setTo("jack.smith@gmail.com")}

etc

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2022

Hi @Diana Gorv 

Weird are you sure it's working fine ?

If your not using else if the last case will never been evaluate and if the first if is false or not working it will take the second everytime.

 

Regards

Diana
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.
July 26, 2022

ah, I should clarify.

You are correct, my last example (with the bolded if-else-else) didn't evaluated. got too excited when I found the answer. So I made a quick edit that did work for me:

if (cfValues['Team']?.value == 'Team A'){
mail.setTo("john.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team B'){
mail.setTo("jane.smith@gmail.com") }

//start a brand new if/else

if (cfValues['Team']?.value == 'Team C'){
mail.setTo("jack.smith@gmail.com")

} else { (cfValues['Team']?.value == 'Team D'){
mail.setTo("joe.smith@gmail.com") }

etc

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2022

Great! If it works !

Suggest an answer

Log in or Sign up to answer