Greetings,
I'm using the 'Labels' field to give access permission for an issue to the company departments, using security levels. For example, the label 'IT_Dpt' gives access to the issue, to all the people in the IT department.
I want to create an automation that will notify via email, all the people in the departments included as labels in the field. So far, I have managed to make it send emails to ALL the people that are members of the departments included in the field, every time a value is added in the field (both on create and on edit). I think it would be better if it could notify only the people that are part of the new department added as a label, so it doesn't spam with emails the ones that have already been notified on a previous edit.
Example:
- I create a new issue, and I add the label 'IT_Dpt'.
- Everyone in the IT department gets a notification email.
- I edit the issue, and I also add the label 'Quality_Dpt' (without removing the 'IT_Dpt').
- Everyone in the Quality department gets a notification email, but the IT employees don't get a new one.
Is this functionality possible?
Thank you in advance!
Hello @d_kamposos
One option is to try {{addedfieldChange.values}} smart value.
For example:
But please test thoroughly as I dont recall if there are any bugs around this field and the smart value..
Sorry for the late reply @Kalyan Sattaluri
Unfortunately you can't use the {{addedfieldChange.values}} values as a receiver of an email. I saw a similar problem in another community thread where OP was able to make it work by creating a new field (Group Picker: single group). He populated that field with the string value of his main field (in my case the 'Labels' values), and then used that group field as a receiver for the email.
In my case I have multiple values in the 'Labels' and I have to loop through all of them using {{addedfieldChange.values}} to populate the new Group Picker(multiple values for me). The problem is that Advanced Branching in automation runs all the branches in parallel and asynchronously, making the results kind of unpredictable and unreliable.
I am currently looking at different solutions for my issue, but I think that the parallel and asynchronous nature of Advanced Branching creates more problems than it solves.
Link for the relevant tread: Automation e-mail to a Jira group from a smart fie... (atlassian.com)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @d_kamposos -- Welcome to the Atlassian Community!
I recall there are known problems with the changelog accuracy of list / multiple-select fields in automation rules, and I recommend fully testing for any use of smart values such as {{addedfieldChange.values}}
That being noted...
It may be possible to do what you ask without using the advanced branch. Instead, iterate over the values in smart value to build a JSON expression to update the group picker field in a single edit. To confirm this, please post your entire rule for context of when / how you want the update made.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Bill Sheboy , thank you for your response.
So far I have this structure for my rule:
Where:
- It looks for changes in the 'Labels' field (Value added on create or edit).
- Assigns {{labels}}={{addedfieldChange.values}}
And for every value in {{labels}}:
- Checks if it contains '_Dpt' (which indicates that the label refers to a department)
- If it passes the check, it adds the User Group containing the employees of the department in the specified field I mentioned in my previous comment. The edit is done as such:
Then I have a second rule triggered when the custom field gets updated, that sends the emails to the groups, using the custom field as the 'receiver'.
As I said, the problem is that the iteration is done asynchronously, so the custom field doesn't always get populated with the correct data.
I would like to hear more about your suggestion to use a JSON expression, as I am not familiar with these more 'advanced' concepts of Jira automation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you want to filter the added labels for ones containing "_Dpt" you may first filter using the match() function and then iterate over the results.
For example...
{
"update": {
"customfield_10108": [
{{#varMatchingLabelsFound.split(",")}}
{ "add": { "name": "{{.}}" } } {{^last}}, {{/}}
{{/}}
]
}
}
How that works...
I have not tested all of this, as the custom field update would work for your site. Please test for your own usage.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy ,
I followed your example and used JSON to update my custom field, and it worked fine! Although there was a little problem after the edit, where I added a condition to check that the field is not empty and then send the emails, but the check failed because (I guess) it runs before the field got the time to be populated, and it appeared to be empty. I solved that problem by ending my rule after the edit, and creating another rule that waits for the custom field to be updated, check the values and send the emails to the groups.
There is one more final issue, and that is not all department labels have '_Dpt' in them. So I have to change the 'varMatchingLabelsFound' smart value a little to check all departments.
Example department labels: Dep1_Dpt, Dep2_Dpt, Department3, Another_one
Do you have any suggestion about that?
Thanks again for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For your two additional questions:
When a field is edited by a rule, the updated information is not visible to the remaining steps of the rule; it still contains the information from the time the issue was loaded by the rule, such as at the time of triggering. That is what caused the need to split the rule. You can eliminate that second rule by using the Re-fetch Issue action after the edit, as that will reload the data before the rule proceeds.
Regarding the different formats for department, you will need multiple variables to solve that: one for each department format. Then split and concatenate them together into one variable before use in the final JSON building expression.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible that you make an example of how this is implemented? I am not familiar with these expressions and I can't seem to make it work...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Successfully using automation rules requires learning and experimentation, and so I encourage you to try this and learn from the documentation. When one just uses rules provided by other they often are unable to maintain and improve them in the future.
I will provide an outline which you may try implementing...
{{#if(not(varDptLabels.isEmpty()))}}{{varDptLabels.concat(",")}}{{/}}{{varDepartmentLabels}}
That expression uses conditional logic to decide when to add a comma between the variables: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/
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.