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
This rule assumes a prior object of the same type already exists to read an increment value from. For the very first object created, there is no 'second most recently created' object to look up, so seed the attribute manually (for example, set it to 0 or 1) on the very first object before relying on the automation for subsequent ones.
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 match the AQL condition, but we need to add an ORDER BY clause to return objects in 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.
If two objects of the same type can be created in very quick succession, both automation executions may read the same 'most recent' value before either has written its increment back, producing a duplicate rather than a truly sequential ID. If strict uniqueness is required, add a uniqueness check downstream rather than relying solely on this automation.
Related articles:
Was this helpful?