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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great! If it works !
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.