How to implement autoincrement field in schema

Hi. Some days ago find the topic where you noticed that autincrement fields avialable in Squidex. But i didn’t find anything in documentation how to add this to my actual schema anf how to use this opportunity.


it is a enhancement for scripting: [IMPLEMENTED] Auto increment in numbers

Thnx. I saw that, but can’t understand the way or i did smth wrong.

  1. I’ve created a new field inside my schema named ‘number’ for example
  2. Than i found Edit Script and put in query section this
    if (ctx.operation === ‘Published’); = incrementCounter();
  3. Than a send from client application new item, but number still null.

Can you help me?

Every time when i add new item to the content i want Squidex to increment his number +1.
First item with number = 1, second item = 2 and etc.
I can’t correctly implement it in code bacause of concerency. In the same time more than 1 user can create an item, and if i will check total number of items before and kust increment it i will get many items with the same number after.

You have to ensure that you are doing your queries for the right action, e.g. Create, not Query

And what about body of expression. Is it right?

The counter needs a name. = incrementCounter('my');

I wish that my orderNumber will be a counter?

You can name the counter how you want. The idea is that you can have as much counters as you want.

That’s what i’ve got last time.

Does this scripts know about all items inside my schema. It ssems that i don’t understand exactly how it works :slight_smile: sorry

Which version do you have installed? The counter is not part of any release yet, only dev version.

It seems that i had old version. Can ‘ctx’ inside scripts knows about total items???

No, it is always per content item.

sad((( now i can’t change version of squidex on our production cloud. I will try to implement smth

Big thnx for you support

1 Like