Recreate records using its old ID

Recreate records using its old ID

  

Good day Guys,

Im currently looking for a way to recreate deleted records using its identical values before it was deleted including its old ID. The requirement is user is editing specific records that has multiple child record which he/she can delete/add new child record. User can discard also all the changes he/she made so i need to revert all the changes made. The approach i currently did right now is populate all the changes to a temporary list var and then trigger delete/create records when user select discard changes option. My problem now is for the deleted records, i cant re assign its original ID during recreation instead it create new record with new ID. IS there a way to recreate the record using its old id?


Thanks,

Percie

Hi Percival,

I'm not sure if I fully understand why you want to re-use an old ID. I think it is possible if you set the auto-number property to 'No' (see image below, but I have to say I haven't tried it myself), and assign the ID programmatically. However, this makes your data prone to errors, and I would not recommend it.


Sam

Hi Sam,

The intention is to make it looks like there's no deletion of record was happened. That is why i want to retain the old id of that record when i recreated the same deleted record. Or if you have any other better approach. 

Thanks,

Percie

Solution

Hi Percival,

Any delete that must be possible to undo must be a soft delete, that is, set some "IsActive" flag to False, and when you query the data use IsActive = true to select only the non-deleted records. If someone wants to undelete, just set the IsActive flag to True again. For permanent deletes, run a timer that collects all records older than X days (or weeks, or months) with IsActive set to False, and delete them.

What you want is not only not possible, but the wrong solution to your problem.

Solution

Hi Percie,


In that case, I would add an Boolean attribute 'IsActive' to the existing entity. If you want to 'delete' the record, you should set it's property to False. Do you want to bring it back to life? Just set it's property to True.

If you want to use the data in your application, you filter out the records with 'IsActive' set to False, so you only have the 'undeleted' records.


Sam

Kilian Hekhuis wrote:

Hi Percival,

Any delete that must be possible to undo must be a soft delete, that is, set some "IsActive" flag to False, and when you query the data use IsActive = true to select only the non-deleted records. If someone wants to undelete, just set the IsActive flag to True again. For permanent deletes, run a timer that collects all records older than X days (or weeks, or months) with IsActive set to False, and delete them.

What you want is not only not possible, but the wrong solution to your problem.

Just beat me to it ;) Glad to see we got the same solution.


Indeed :)

Thanks a lot guys..i will try to implement your suggested approach..


Thanks,

Percie