Jira Automations Send email to new/changed person in user picker field fieldChange

Joshua Wyss November 16, 2022

I want to be able to use Jira Automations to send an email to the new person in a user picker field (Assignee, custom, etc.) and not all people. I want this to trigger on 2 different user picker fields so I want to use the {{fieldChange}} smart value but it does not provide the email address.

 

Scenario 1

For example, when a new person is assigned to a Jira Issue I want to trigger and send only that new person an email.

Scenario 2

When a new person is added to a multi-person person selector custom field I want to trigger and only send an email to that new person and not others.

 

I have tried

In the 'Send an email" action I've tried adding the following to the "To:" field but none have succeeded.

  • {{#fieldChange}}{{emailAddress}}{{/}}
  • {{fieldChange}}
  • {{fieldChange.to}}
  • {{#fieldChange}}{{emailAddress}}{{/}}
  • {{addedfieldChange.values}}

The Error:

Send Email:

Could not send email, the 'To' address field is empty. If you have referenced a field it may be empty.

The same error happens for all options.

Related questions:
https://community.atlassian.com/t5/Jira-Software-questions/How-can-I-get-email-address-from-changed-field/qaq-p/1484803

https://community.atlassian.com/t5/Jira-questions/Jira-Automation-How-to-send-mail-only-to-added-User/qaq-p/1443188

3 answers

1 accepted

1 vote
Answer accepted
Simon Schwab Mariño February 16, 2023

Hey @Joshua Wyss

We also wanted to perform specific actions for newly added users only, ignoring the existing users in a user picker field. 

Here is the approach I went with (in this scenario the user picker field is "Approvers"). It's very close to @Bill Sheboy proposal but without the need of using a comment/additional custom field. It also works for "adding, removing, and re-adding" scenarios and you can monitor as many fields as you like with a single automation, removing the need to maintain the same email template in multiple locations.

As Bill pointed out as well, the {{fieldChange}} behaviour seems to be broken atm (or the documentation is ambiguous). You might want to revise the automation once that's fixed/changed.

1. Set a trigger to trigger on added values only (naturally, the Edit issue constraint is optional).

2023-02-16 19_23_50-Automation - Jira.png

2. Use advanced branching to execute the branch for each value in <user_picker_field> and assign the individual values to an "iterator variable" of your choice (here it's approver).

2023-02-16 19_25_21-Automation - Jira.png

3. Use the advanced compare condition to check if the {{fieldChange.from}} value (which appears to be a string with all existing account IDs) does not contain the respective user's account ID (here {{approver.accountId}}). Because if it doesn't, that means it was added just now.

2023-02-16 19_27_11-Automation - Jira.png

4. Use your variable containing the user object (in this example it's {{approver}}) to access the user property you need for any action you might want. To match your use case, I sent an email to the newly added users, as shown in the full depiction below.

2023-02-16 19_22_01-Automation - Jira.png

I hope this helps.

 

Best
Simon

Serena Romeo March 30, 2023

Hi Simon, 

I tried your method and it is working, but I noticed that If I add two ore more users in my user picker field, in the email's "to" I only see myself and not the others users email addresses.

Do you happen to know a way around this?

Thank you,
Serena

Simon Schwab Mariño March 30, 2023

Hey Serena

To clarify: I assume you're testing the automation by adding yourself and others to the user picker field. In the consequently received email, you only see yourself as a recipient, and you're now wondering if it's possible to have all recipients visible in that email's "to" field. Is that correct?

If that's the case, you're experiencing the "desired" behavior. The automation executes the For each: Smart value branch for every new user. Thus, it sends one email per added user instead of one email to all users, which, I guess, is what you want.

Unfortunately, I wouldn't know how to achieve this with the limited operations available in Jira Automation or smart values.

Best
Simon

Like Serena Romeo likes this
Serena Romeo March 30, 2023

Thank you Simon, you explained it way better than I did! :)

Bill Sheboy
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.
March 30, 2023

Hi @Serena Romeo -- Welcome to the Atlassian Community!

You could try using the field change smart value which seems made to do this:

{{addedfieldChange.values}}

Please look here for more information: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--fieldChange--

Kind regards,
Bill

Like # people like this
Joshua Wyss October 17, 2023

Thank you much @Simon Schwab Mariño ! That totally worked!

Another employee here was annoyed by the duplicated emails and stumbled across my post here. Did not realize you had replied. I and every developer here thank you. 🙇

👏👏👏

0 votes
Mike Vitale January 4, 2024

Hello, @Simon Schwab Mariño!

I could use your expertise here. I followed the setup steps above, but in the end I'm still seeing notifications being generated multiple times for the same user, even after they've received their 1st email notification when added to the field. Here is the current automation build. Would love any assistance that could be provided:

Work Participants Email Notification.jpg

The behavior I'm seeing is as follows:

- Added John Williams as a Work Participant > John received an email

- Then added Christine Anna as a Work Participant > 2 emails were generated, both with John and Christine in the "to:" field

Any thoughts on how to avoid the multiple emails? I would like it to be set so that John only receives an email once he's added, and not again when other users like Christine are added.

Bill Sheboy
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.
January 7, 2024

Hi @Mike Vitale 

Smart values are name, spacing, and case-sensitive.  And when they do not match a known value, they evaluate to null and often silently fail to work as expected.

Your condition at the start of the branch is referencing {{Work Participants.accountId}} but that does not match your branch variable of {{workparticipants}}  Is that what you intended to check?

Kind regards,
Bill

Like # people like this
0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2022

Hi Joshua,

I don't have time to fully investigate right now, but here's some thoughts. 

1. You should be able to do this now. Just make your trigger as a Field Value change to Assignee and send the mail to the Assignee. 

2. I am thinking that you could use the #lookupIssues function in some way to get the account ID of the person added. Then dump that into a custom user picker field (hidden from the screen). And then send an email to that custom field. 

Bill Sheboy
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.
November 16, 2022

Hi @Joshua Wyss 

Yes, and...to John's answers...

For your second case, you are encountering the problem where changelog seems not to be working lately with smart values for multi-select and multi-value fields (user-picker, fixVersion, labels, etc.)  Until that is fixed (added?) work-arounds are messy.

One approach is to capture values (i.e. flag) in another custom field/comment once an email is sent:

  • iterate over the values in the custom field using an advanced branch
    • check with an if condition for the absence of the value in the other custom field/comment
    • send your email using the branch iterator variable to get the email address
    • add the flag value to the custom field/comment

This will not handle the case where someone is added, removed, and re-added.

Kind regards,
Bill

Joshua Wyss November 18, 2022

@John Funk I did the route you suggested in #1 where I cloned the automation with one triggered by Assignee and the other triggered by my customer user field.

This isn't the most efficient way to build this because now I maintain the same email content in two automations.

I looked into your suggestion #2 but did not understand how it would be implemented.

 

My goal was to put multiple user fields in the same trigger and access the email address of whoever triggered the Automation. I think this is just a missing feature as @Bill Sheboy suggested.

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 17, 2023

@Joshua Wyss  - Did you try to implement Bill's suggestion? 

Joshua Wyss February 28, 2023

@John Funk no I have not done either suggestion. I put this aside since I got it working at the minimal level. I am contacting a couple of users to see if they get copied when others are added, and if they do I'll implement @Bill Sheboy 's suggested solution. Either way I'll reply with what I learn.

Here is what I currently have:

2023-02-28 14_42_17-Clipboard.png

Like John Funk likes this
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 28, 2023

Great! Glad you are making progress. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events