Implementing Folder-like Structure with Limited Visible Records in Frappe

I’m trying to replicate a folder-like structure within Frappe, where only the latest 3 records are visible at any given time. Any new records exceeding this limit should be automatically moved to a backup location (another doctype).

In a shell script, I’ve successfully implemented this behavior with a backup folder and file. Essentially, when a 4th folder is created, the oldest one is moved to the backup. I’d like to achieve the same within Frappe, but I’m not sure about the best approach.

Can you describe your use case a bit? Designating a separate custom doctype as a backup “location” sounds like a very un-Frappe design pattern. I think there’s probably a much better way to accomplish what you’re trying to do.

That said, this would be fairly trivial to implement using a Server Script triggered either on Insert or on Submit. Just query the doctype list, see how man documents you have, and copy/delete if there are more than three.