Secuencial Customfield

I need to implement a numeric customfield that is secuencial.

The idea is when I create an issuetype X in a project, automatically this custofield will have value = previousvalue +1, where previousvalue was assigned to the last instance of issuetype X created in any project. In this way I can a hold a correlative associated to all instances of issuetype X.

Any hints?

Thanks in advance.