How to use list functions (like size, average) on Assets object attributes in Automation
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
In certain use cases, we would like to use list functions like size, average etc. (as listed here) on object attributes in an Automation rule. We can't use them directly on the attribute smart values as these values are stored as string. The below article explains how to utilize these functions on Assets object attributes.
Solution
Use Case 1: To find the average of values stored in an Assets attribute of multiple objects
Let's say, you have an attribute called "Amount" of type integer in an object type. You have an Asset object field called "Contract" which can store multiple objects of this object type. Your requirement is to calculate the average of the values stored in "Amount" attribute of objects stored in "Contract" custom field.
- Go to Project settings > Automation > Create rule . Set the trigger as required.
Create a variable to store the attribute values(in this case, the name of the variable is amount ):
{{issue.Contract.Amount}}
To calculate the average of the above values, you can use the below smart value:
{{amount.split(",").average}}
The split() function helps to break the string into a list which allows us to use these functions. Similarly, you can use functions like size, max, min to find the desired value. You can use the above smart value as needed in your automation rule to display the average.
Use Case 2: To find the number of users stored in a multi-user type attribute of the object returned by "Lookup objects" action
Let's say, you have an object type called Software which has an attribute called "Users" which can store multiple users and depicts users who have access to this software. You have a text field called "Application" which stores the name of the Software which is the same as that of the name of the object stored in the Software object type. Your requirement is to find the total number of users who have access to this software.
- Go to Project settings > Automation > Create rule . Set the trigger as required.
Click on New action > Lookup Objects action and specify the below IQL:
objecttype = "Software" and Name = {{issue.Application}}
You can use the IQL based on your requirement
Create a variable to store the "Users" attribute value(in this case, the name of the variable is users ):
{{lookupObjects.Users}}
To calculate the total number of users stored in this attribute, you can use the size function as shown in the below smart-value:
{{users.split(",").size}}
You can use the above smart value as needed in your automation rule to display the total number of users added in the multi-valued attribute.