Auto-incrementing numbers as page titles in Applications

In our wiki, I have an Application I designed to be used to file Expense Reports. Ideally, I would like people to be able to click “Add Entry” and have it create a new page with an incrementing integer identifier rather than have them having to pause and come up with a (relatively meaningless) page title. The ID could be linked to our books and printed on the check as a permanent reference to that expense in the system.

Is there any way to make this happen today? Thanks!

Yes you can do that. It’s just that the app that AWM generates doesn’t support this. So you’ll need to modify the AWM-generated app or create a custom app.

Here’s how you do that programmatically:

You could also check out and check how it does it.


Re AWM this is Loading... If someone could send a PR that would be awesome :wink:

What is a PR?

PR = Pull Request = About pull requests - GitHub Docs :slight_smile:

Thanks, I’ll check this out when I get a chance.

You just created a huge race condition. Actually you rely on that nobody creates a document while you are executing


So this is not at all guaranteed that it the id is unique!

Assume two users execute your code at the same time.
A gets start index 5 (B has not yet saved)
B get start index 5 (A has not yet saved)
A and B increment the index by one, meaning both have index 6 now.
B saves (document has index 6) and title ‘Doc 6’
A save (document has index 7) and title ‘Doc 6’

–> Page titles are no longer unique.

The timeframe to get into this situation is small, yet it exists.

And no, I’m not going to fix it. I hate fixing race conditions (because it is often really hard) when I have to, I don’t do it for fun.

thanks @rbr
there are some errors in the code.
For this reason I deleted the code

You might want to have a look at

It would be nice if that extension would be improved to support specifying multiple unique groups and not have just a single, common one, but it’s still something that might ensure you get a thread safe incremental number.

Thanks @Enygma I wrote a code and solved the problem

Yes you can do that. It’s just that the app that AWM generates doesn’t support this. So you’ll need to modify the AWM-generated app or create a custom app.

Hi, I am finally coming back around to this. How would l modify the AWM-generated app? Is that stored somewhere on disk when it is created, or stored in MySQL, or…? Not being a java person, the XML-with-embedded-code thing is pretty mysterious to me. I tried to look at the AWM code to see how it writes the application but couldn’t figure it out (in five minutes). :slight_smile:


You’d need several days. I’d say at least 2-3 days of work to understand the programming model of XWiki. To get started:

If you don’t have that time, you should consider that this feature doesn’t exist FTM and wait for it to be implemented in the future. This is is something we’d like to add but it’s not on the roadmap ATM. Note that you can also sponsor the development of it if you really need it, see . That’s a good way to contribute to XWiki too :slight_smile:

Looks like you haven’t read .

Thank you for all of these links. I was having a hard time google searching to find this info, so having the direct links helps significantly. I will start digging in.

Looks like you haven’t read .

The sad thing is, I found that page and scanned it, but did not find that section. Thanks for referencing it directly.

Hi – I am relatively new to Xwiki – but am having the same need – and hence issue to solve.
I found an example of AUTO INCREMENTING A PARAMETER under the TASK MANAGER APPLICATION example – the code is within in the SHEET page of the AWM code set. The number parameter of the TASKMANAGER (object) is AUTO INCREMENTED – each time a new TASK is created.
The HEADING for the parameter in the associated LIVE TABLE has been TRANSLATED TO “KEY”.
This might help you to find a way to solve your requirement.