Forum Discussion
_anomDiebolt_
7 years agoQrew Elite
This task is easy to accomplish with scrip and there is no need to comprimise your original goal of deleting all but the most recent 10 records.
Here is a working demo with (1) a button to delete all but the ten most recent records in Table #1 and (2) a second button to add new records to Table #1 (to keep the demo fresh for new visitors).
Delete All But Top Ten ~ Tasks
https://haversineconsulting.quickbase.com/db/bncb83cqt?a=td
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=615
Notes
(1) The basic algorithm is to obtain the [Record ID#]s for the first 10 records and then form a query that asks for all records where the [Record ID#] is not equal on of these ten values using the XEX and AND query operators. The resulting set of records is then deleted using API_PurgeRecords.
(2) You should use extra care in using this script to insure you do not accidentally delete records since API_PurgeRecords does not ask for confirmation before purging records. Take the normal precautions of working in a copy of your database and temporarily substitutie logging for deleting until you are sure you have correctly implemented your version of the script..
(3) The scripts are implemented through a Tasks table for convenience of the demo. In an actual deployment the buttons that invoke the scripts might be placed in a more localized part of the workflow.
(4) The script that adds records uses the underscore library to select 10 random records from a set of hard-coded list of fifty records. This is done solely to make the demo appear fresh although other users may have run the scripts during thier session.
(5) The scripts use backtick characters (ie ') for string interpolation
Here is a working demo with (1) a button to delete all but the ten most recent records in Table #1 and (2) a second button to add new records to Table #1 (to keep the demo fresh for new visitors).
Delete All But Top Ten ~ Tasks
https://haversineconsulting.quickbase.com/db/bncb83cqt?a=td
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=615
Notes
(1) The basic algorithm is to obtain the [Record ID#]s for the first 10 records and then form a query that asks for all records where the [Record ID#] is not equal on of these ten values using the XEX and AND query operators. The resulting set of records is then deleted using API_PurgeRecords.
(2) You should use extra care in using this script to insure you do not accidentally delete records since API_PurgeRecords does not ask for confirmation before purging records. Take the normal precautions of working in a copy of your database and temporarily substitutie logging for deleting until you are sure you have correctly implemented your version of the script..
(3) The scripts are implemented through a Tasks table for convenience of the demo. In an actual deployment the buttons that invoke the scripts might be placed in a more localized part of the workflow.
(4) The script that adds records uses the underscore library to select 10 random records from a set of hard-coded list of fifty records. This is done solely to make the demo appear fresh although other users may have run the scripts during thier session.
(5) The scripts use backtick characters (ie ') for string interpolation