#GeneralInterest -: Hi all , I have one scenario, Let say i have one table

#GeneralInterest -: Hi all ,
I have one scenario, Let say i have one table Employee in this table, i have 3 columns RowId (Primary Key ),EmpId(int) and EmpName(text),EmpId and EmpName should be unique and from UI if two users are trying to insert same value at same time, then these entry should go as overwrite instead of creating two separate entries in database, I have tried using Unique Key constraint but if we are trying to insert same record which is exist in database that time write to database node is failing and i am getting “Unique key constraint violation error”, for work around i am checking record is exist in database or not, if yes then updating existing record on Write to Database node and also using unique key constraint ,but any other way to do this because two users are running flow simultaneously with same value so whose entry will go first that we are not sure?
Kindly suggest how to handle?

OriginalPostID-217893

OriginalPostID-217893

  Discussion posts and replies are publicly visible

  • You can use Query Database node as mentioned by stefanh791 and it will help you to update the record in Database.
  • @jasmins - In the exception flow of the sub process you can fetch the record with EmpId and EmpName(which are the unique keys) in script task and then made updations to the CDT and pass it to the "Write to Data Store Entity" node or create a subprocess with the DB Interaction process model and it will update the record. In other words, if id/primary key is already present it will update. You dont need to write any logic for that.
    Please refer the screenshot and make updates/enhancements accordingly.
  • I wouldn't like to really agree with the statement 'It is always good to have DB Interactions in a sub-process and configuring a exception timer on the sub-process in case the insertion or updation fails.' and it completely depends on the scenario and the design. I believe that the design as mentioned above is not completely fool proof and the process need to run on an assumption that it fails in one and only one case.

    For instance, let's take a case where the Write to Database node has failed because of the reasons other than the Unique Constraint Violation Exception while updating a particular record. Also let's assume that the node has failed while trying to insert data into a column of more than its length or trying to insert a in-existent key when a foreign key is expected. It might not really make sense if the process takes exception path in these cases without resolving the issue and in-fact that might create new issues.


    And with regards to update operation, again I wouldn't like to completely agree with the statement that we don't need to do anything because it depends on what you desire for. So if you are looking forward to make an update and also make the operation safe from concurrent updates, then I would suggest going through the documentation at forum.appian.com/.../Data_Locking_Strategies.html. And @stefanh in his previous comments has pointed to a link where you can see some good comments made by him and other practitioners. I suggest taking a call post analysing all the available options and also after analysing the scenarios and running through the assumptions.