How can I automate a counter for assets to increase every time I create a new object in my schema?
Asked by Bea H:

Hey!   

We use assets in Jira to track our IT assets, but we also use it for systems and people.   
They all however share keycounter, even though they are in different schemas.

For example: I create an It assets, and that generates the key IT-2734

Then I create a new system in our system library, and that gets the key SL-2735

**This creates an issue for us, since we want to keep a counter on our IT-assets separately.**   

My Question is basically, is there a way to create a counter with some automation that reference ONLY our IT asset schema? Not the other schemas. So when I create an asset, it will look for the previously created and add a number to it as a field in the asset.

I have looked all over and not found a solution to this, so would appreciate some help! Thanks!


Answers:
author: Robert DaSilva - Adaptavist
body: [@Bea H](/t5/user/viewprofilepage/user-id/5539277) You should be able to easily view your total number of assets from the "Object Schema Selection" Screen. This should list each schema you have, and the total number of objects each have.

You may need to move some of your items, such as your users, to a new schema in order to have these listed separately.

Here's how it should display when you click the "Assets" button in the top menu inside Jira.

![Screenshot 2024-08-29 at 11.35.11?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/344590i0F3A9EBA32105897/image-size/large?v=v2&px=999 "Screenshot 2024-08-29 at 11.35.11?AM.png")

comments: author: Bea H
body: Thank you for the answer, but it was not exactly what I was looking for, I want it as a custom field in the object view, instead of the key number that counts all schemas.  

When an object is created a key is generated, for example KEY-1, and the next will have KEY-2, but if I create an object in another schema, and then go back to the first schema, the next number will be KEY-4.


author: Robert DaSilva - Adaptavist
body: [@Bea H](/t5/user/viewprofilepage/user-id/5539277) Ah apologies, let me see if I understand you correctly then.

* You have an Assets Schema specific to tracking IT assets
* The default "Key" value iterates up with new assets, but also iterates up with assets created inside other object schemas
* You need a specific identifier, similar to the default Key, where the counter only iterates up for items inside this IT Assets Schema

I do not believe Assets supports this by default. You might be able to accomplish this via Jira Automation however.

1. Create a new attribute in your Assets Schema configuration for your unique counter value
2. Create a new Global Jira Automation
3. Select the "Object" trigger under the "Assets Triggers" filter
   * Configure the trigger to only apply to new assets created inside your desired schema
4. Add a new Action, and select "Lookup Objects" from the same Assets filter
   * You will need to insert an AQL query here to find the objects you're looking for. In automation, the Lookup Objects function only returns up to 100 results, so you will need to include your specific counter field as the "Order By" field, ensuring you do this in descending order.
   * Once you have the objects list returned, you should be able to pull the value in the counter attribute, and iterate that up one
5. Add a new Action, and select Edit Object
   * Update the counter field to the next integer value

The specific configuration of this automation rule will require some massaging, and all existing entries will need to have this new attribute for the counter filled in before you enable this rule.

I'm going to play around with this in my sandbox and see if I can provide more specific instructions on the AQL query itself, but this should be a good overall framework to get this solved.


author: Bea H
body: Hey Robert! Thank you for looking in to this and helping out! It worked exactly how we wanted it to work!   

This is the automation we went with:

When Object created: in IT Assets  
Then Lookup objects: "ObjectType in (Laptops, Phones, Monitors, Peripherals, Desktops, Printers, Tablets, "External Storage", Miscellaneous, "Network Equipment" ) AND "IT Asset Number" is not EMPTY ORDER BY "IT Asset Number" DESC"  
And Create variable: {{ITA}} and Smart Value "{{lookupObjects.first.IT Asset Number}}"  
And Create Variable: {{NewITA}} with Smart Value "{{#=}}{{ITA.replaceAll("\[\^0-9\]", "").asNumber}} + 1{{/}}"  
And Then Edit Object attributes: Update field IT Asset Number with "ITA{{NewITA}}"

This is gonna solve some major headaches for us!   
Thank you so much again!   
Have a nice day!


author: Robert DaSilva - Adaptavist
body: [@Bea H](/t5/user/viewprofilepage/user-id/5539277) Glad you were able to get it working! Happy to have helped.


Tags: assets

cloud

jira-service-management

jira-service-management-cloud