I would like to add sequential numbering to each entry, which is obtained from a global field. After saving the entry, the global field should be assigned the next number (+1). Does anyone have any idea what the code for it would look like (module)?
You can use event hooks to hook into the saving process for elements to achieve this behaviour. In particular, you can use the hooks
Entry::EVENT_AFTER_SAVE to perform some custom action before or after an element is saved. Both hooks receive a boolean argument indicating if the element is new. You can use that to either set a starting value for your ID field (if the element is new) or update the global counter (if the element is not new).
However, your suggested workflow doesn't appear to be very thought out. For one, what if an editor edits the People ID manually? This would mess with the counter in unexpected ways, and in turn mess up subsequent IDs. Also, I'm not sure why you need a custom ID field and the global counter, but it looks like you're trying to replicate functionality that you already get for free out of the box with Craft:
- If you only need a unique ID for each person, each entry has that by default once it's saved to the database, so you could just use those.
- If you need a sequential ID only for people … why? If you just want to know the ordinal number of a person (i.e. how many people there are before a specific person), you can use a simple count query with the positionedBefore parameter.
- For the global counter: If you only need that to generate the sequential IDs, you don't need it at all if you use one of the suggestions above. If you need it to get a total of all people, you can use a count query instead.
If you edit your question to include the actual problem you're trying to solve, I'm sure someone could suggest a better approach!