Intercepting Record Merge Events and Tracking in Deletion Registry
I have a need to intercept record merging events (deduplication).
In the case of merging records, store information about the ID of the deleted record (which was merged and deleted) in the registry of deleted objects, which has already been created, but only deleted records are written there, and not those that were a duplicate and were simply merged and, accordingly, deleted.
Implement a mechanism that will store information about the user who performed the merge and the exact time of the operation. Is this even possible?
Like
Theoretically it's possible. When triggering the merge the MergeEntityDuplicatesAsync method from the DeduplicationService is triggered. This is a public method that can be overridden. The body of the request is a JSON like below (in this case I was merging two documents):
{"schemaName":"Document","groupId":1,"deduplicateRecordIds":["054ac2b7-6840-4cc8-881e-b268b0891459","c467e547-cbff-4ae7-b146-93eff47f1ce6"],"mergeConfig":"{\"Number\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\",\"Date\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\",\"Account\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\"}"}
deduplicateRecordIds is an array with Ids of two records that I selected before triggering the merge.
In the mergeConfig body we have \"Number\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\ - this is an Id of the record that was left in the app after the merge. So we have
"054ac2b7-6840-4cc8-881e-b268b0891459","c467e547-cbff-4ae7-b146-93eff47f1ce6
in the deduplicateRecordIds array and 467e547-cbff-4ae7-b146-93eff47f1ce6 is left in the app. This means that 054ac2b7-6840-4cc8-881e-b268b0891459 was removed. So this Id should be added to the log table (for example using InsertQuery class). As for the user that performs merge - we can try retrieving this information using UserConnection.
Alternatively you can dig into the possibility of overriding the base merge button click (that will also trigger the "DeduplicationActionProcess" business process (see the process log after the merge is triggered)) and bind calling your custom business process that will do the same operation as the base process (create a copy of the process and trigger it instead of the base process) and using it you will also be able to log deleted record and user who performed the merge.
Theoretically it's possible. When triggering the merge the MergeEntityDuplicatesAsync method from the DeduplicationService is triggered. This is a public method that can be overridden. The body of the request is a JSON like below (in this case I was merging two documents):
{"schemaName":"Document","groupId":1,"deduplicateRecordIds":["054ac2b7-6840-4cc8-881e-b268b0891459","c467e547-cbff-4ae7-b146-93eff47f1ce6"],"mergeConfig":"{\"Number\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\",\"Date\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\",\"Account\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\"}"}
deduplicateRecordIds is an array with Ids of two records that I selected before triggering the merge.
In the mergeConfig body we have \"Number\":\"c467e547-cbff-4ae7-b146-93eff47f1ce6\ - this is an Id of the record that was left in the app after the merge. So we have
"054ac2b7-6840-4cc8-881e-b268b0891459","c467e547-cbff-4ae7-b146-93eff47f1ce6
in the deduplicateRecordIds array and 467e547-cbff-4ae7-b146-93eff47f1ce6 is left in the app. This means that 054ac2b7-6840-4cc8-881e-b268b0891459 was removed. So this Id should be added to the log table (for example using InsertQuery class). As for the user that performs merge - we can try retrieving this information using UserConnection.
Alternatively you can dig into the possibility of overriding the base merge button click (that will also trigger the "DeduplicationActionProcess" business process (see the process log after the merge is triggered)) and bind calling your custom business process that will do the same operation as the base process (create a copy of the process and trigger it instead of the base process) and using it you will also be able to log deleted record and user who performed the merge.