An OS webhook(= exposed REST API) receives contract-data and is repetitively called. Each posted contract brings its own unique external Contract Id and is stored in a OS db entity. In detail : the OS Rest POST action stores the contract-data (incl. Contract ID) in a OS entity by doing a Create immediately followed by a CommitTransaction. Before the Create is done (within the same OS POST Action) a check is done to find out if the Contract ID already exists in the OS db. In the latter case the Contract isn't stored in order to prevent having contracts with identical external Contract-ID's in the OS db.

Despite doing so I do sometimes find double identical Contract-IDs in my OS db entity. How come? Noticable is that with these cases the webhook-calls (posting the Contracts with identical Contract-IDs) have taken place several times within one second. I already build in a 3 seconds waiting-time in the OS POST action in between the check and the create. But that didn't prevent the double Contracts.  Can anyone advise me what to do next to prevent this from happening?  Does anyone know if more instances are executed simultaneously and at the same time within OS by the frequent webhook-calls ?

Solution

Hi Adam,


The safest way to do it is insert a unique index in the database for that field (you also want it index because you should be doing querys on that field).

You can do that like on the image below:

1. Double click the entity
2. Navigate to tab indexes
3. Create a unique index on the field ContractId

If you do that, the code would throw an exception when trying to avoid a duplicate contract id beacuse the database will protect you from that inconsistency.


Solution

Thanks. That worked.