Automatically increment Assets integer attribute using automation
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
Learn to use automation to increment a numeric attribute for Assets objects of the same type. This can be useful when each object type requires a unique, sequential ID.
This article outlines the steps to create an automation rule that triggers whenever a new object of a specific type is created.
Solution
Add an integer attribute to your object type
Navigate to Assets and open the object schema containing the object type that requires auto-increment. Select the object type and add a new integer attribute.
Automation to auto-increment value
The rule retrieves the value of an integer attribute from the second most recently created object (since the most recent is the one just created), increments it by 1, and assigns the result to the new object.
Go to Settings > System > Global Automation. Automation components for Assets objects can only be used in Global Automation.
Create a new rule:
Trigger: Object created. Select the relevant object schema.
Condition: AQL condition. This will restrict the scope of the rule to specific object types, in this example, 'Laptops.' The AQL should be like:
objecttype = "Laptops"Action: Lookup Objects: This will collect the increment value from the last created object. The AQL used here should be the same as the AQL condition, but we need to add an ORDER BY clause so the objects are returned in the newest to oldest order. The AQL should be like:
objecttype = "Laptops" ORDER BY Created DESCAction: Create Variable. This will store the value of the object returned from the Lookup Objects action. Variable name: number Smart value:
{{lookupObjects.get(1).Increment}}Action: Edit Object Attribute. This will edit the attribute in the newly created object, incrementing its value by one using a math expression. On the dropdown, select the integer attribute that you're using for the auto-increment. Enter the smart value to set the value for it:
{{#=}}{{number}} + 1{{/}}Ensure there are no trailing spaces on the above smart value (even copying and pasting this may result in it; manual verification is recommended).
Save the rule.
The integer attribute of newly created objects of that type will be automatically incremented.
Related articles:
Was this helpful?