I have some challenges I really need some help with.
I'm developing a ContractManagement app. For this I created an entity 'Contracts' and an entity 'ContractVersions'.
The general idea is that the user should be able to, for instance, renew a contract by editing a version, and this new version is stored as a version with a versionnumber 1 higher than the previous related to the same Contract. Moreover a new (first) version related to a new contract should automatically be assigned versionnumber 1.
I have managed to use an assign to create a versionnumber=versionnumber + 1.
After creating a new Contract, the new first version of this contract is being assigned a versionnumber 1 higher than the highest version of an existing Contract, not being the Contract for which I am creating a first version. To clarify:
Creating a Contract and 2 versions:
Contract[Id=1] → Version 1, Version 2
This is ok but when creating a new Contract this happens:
Contract[Id=2] → Version 3
Ofcourse I want it to be Version 1 because it's ContractVersion 1 under Contract[Id=2].
How can I manage to create a versionnumber +1 only fetched from the specific contractversions under this specific contract[Id]? Do I need to create an advanced query to fetch the highest versionnumber related to this contract[Id], and subsequently assign a versionnumber OutcomeAdvancedQuery+1? Or is there some simple solution to this problem/challenge (maybe some refresh action)?
For an update I want the user to edit the contents of the highest contractversion related to a specific Contract[Id]. After this edit the Contractversion is not updated but a new ContractVersion with a versionnumber + 1 is created. Aside from the problem described above, this seems to work.
However, I also want the user to create a first version for a contract in a completely empty edit-screen. However, if I create a first version of a Contract I get an edit-screen/form pre-filled with data from the latest created version (not necessarily related to the same contract).
How can I set a condition to present an empty edit-screen/form? And, related to the first problem, how do I set the pre-filled data to be from the latest ContractVersion related to the specific contract I'm editing?
To fetch the latest ContractVersion of a Contract for edit, I have to order the list by VersionNumber Descending (DESC). I managed to do this by using an 'order by'. If I test the query the highest VersionNumber is the first record in the list. Also the edit screen is pre-filled with data from this record with the highest VersionNumber: So far so good.
However, the table showing Versions still orders the records Ascending! Any ideas about the cause of this behaviour?
For people kind enough to have a look I have created a small espace to show these problems (see attachment).
Any hints, solutions and easy solutions for my challenges? I would really appreciate it!