How to Calculate the Sum of Asset Objects in Jira Using Automation and LookupObjects


Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Summary

A customer required a way to calculate the sum of variables that contain asset objects using Jira Automation. The initial approach encountered issues with correctly calculating the size of specific asset attributes within a custom field. A workaround was implemented using lookupObjects and size functions to correctly calculate the total number of objects in the custom field.

Environment

  • Jira Cloud
  • Automation Rule: Jira Automation using smart values
  • Custom Field: "Affected Services (Assets - 10084)" contains asset objects
  • AQL (Assets Query Language): Used for querying objects within Jira Assets

Diagnosis


The initial approach used to calculate the sum of asset objects in the custom field "Affected Services (Assets - 10084)" failed because the “Sub-Services” attribute was not calculated correctly. The size function, when applied directly to the "Sub-Services" attribute, did not return the expected result due to the specific structure of the asset data.

Cause

The issue occurred because the "Sub-Services" attribute in the "Affected Services (Assets - 10084)" field is a complex list, and the size calculation was not functioning as expected when directly accessed. The raw values in the field required additional formatting and manipulation to be processed correctly by the automation rule.

Solution

A workaround was implemented using lookupObjects and the size function. The automation rule was designed with the following components:

  • Create Variable: SubServicesList
    Retrieves the raw values of the "Sub-Services" field:
{{issue."Affected Services (Assets - 10084)"."Sub-Services"}} 

This step extracts the list of "Sub-Services" associated with the custom field, providing a view of the raw values for debugging.

  • Create Variable: SubServiceSingle
    Converts the list into a JSON string array format and applies replacements to clean up the data:

{{issue."Affected Services (Assets - 10084)"."Sub-Services".AsJsonStringArray.replace("[","").replace("]","").replace(", ","\",\"").replace("\"","")}} 
  • LookupObjects Query
    Use lookupObjects to retrieve all objects of the "Sub-Services" type that match the values in the list:


objecttype="Sub-Services" AND Key IN ({{issue."Affected Services (Assets - 10084)"."Sub-Services".AsJsonStringArray.replace("[","").replace("]","").replace(", ","\",\"").replace("\"","")}})
  • Calculate Object Size
    The lookupObjects.size smart value was used to calculate the total number of objects:
{{lookupObjects.size}} 


If/Else Condition
The final automation rule uses the lookupObjects.size value to manipulate the issue ticket based on the number of objects identified.

This approach ensures that the size is calculated correctly by handling the complex structure of the asset objects and processing them through lookupObjects.


Last modified on Sep 15, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.