Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to make an automation run, based only on the new values added in multiple values field.

d_kamposos April 15, 2024

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!

1 answer

1 vote
Kalyan Sattaluri
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.
April 15, 2024

Hello @d_kamposos 

One option is to try {{addedfieldChange.values}} smart value.

For example: 

  • Trigger = Field Value Changed for Labels
  • Log Action = {{addedfieldChange.values}}
  • if Condition = smart values => 
    • {{addedfieldChange.values}}
    • equals
    • Empty (leave blank)
    • Then you can use this smart value in the To email..

But please test thoroughly as I dont recall if there are any bugs around this field and the smart value..

d_kamposos April 23, 2024

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)

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.
April 23, 2024

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

d_kamposos April 24, 2024

Hello @Bill Sheboy , thank you for your response.

So far I have this structure for my rule:
rule.png

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:
add fields.png

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.

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.
April 24, 2024

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...

  • action: create variable, to extract the found matching additions
    • name: varMatchingLabelsFound
    • smart value: {{addedfieldChange.values.match("(.*_Dpt.*)").join(",")}}
  • condition: check that {{varMatchingLabelsFound}} is not empty
  • action: create variable, to build the JSON for adding the values
    • name: varJson
    • smart value: 
{
"update": {
"customfield_10108": [
{{#varMatchingLabelsFound.split(",")}}
{ "add": { "name": "{{.}}" } } {{^last}}, {{/}}
{{/}}
]
}
}
  • edit issue: using advanced edit, and supplying {{varJson}} as the expression.

 

How that works...

  • The first variable uses a regular expression to filter the added labels to find the ones containing "_Dpt", and producing a comma-separated values list
  • Use a condition to confirm any matches were found
  • That list is split() and iterated to dynamically build the JSON to add the values
  • As the JSON is built, the trailing comma is not added for the last item; automation use of JSON does not accepted any straggling commas 

 

I have not tested all of this, as the custom field update would work for your site.  Please test for your own usage.

d_kamposos April 29, 2024

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!

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.
April 29, 2024

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.

d_kamposos April 30, 2024

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...

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.
April 30, 2024

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...

  • Earlier I explained how to search for values containing _Dpt so use that to create a variable, which we could name varDptLabels
  • Use the same method to find other matches, such as for Department, stored in a variable, which we could name varDepartmentLabels
  • Those could be merged by concatenating, cleaning up, and storing in a new variable, which we could name varLabelsFound

{{#if(not(varDptLabels.isEmpty()))}}{{varDptLabels.concat(",")}}{{/}}{{varDepartmentLabels}}

  • Use that last variable as described earlier for creating the JSON

 

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/

Suggest an answer

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

Atlassian Community Events