Truncating lists

LabKey Support Forum
Truncating lists Olivier  2015-04-14 06:13
Status: Closed
 
Hi,

How can I truncate all entries from a list (SQL: truncate) without selecting and deleting the rows?

Thanks,
Olivier
 
 
Jon (LabKey DevOps) responded:  2015-04-14 10:19
Hi Oliver,

Are you currently using the 15.1 version of LabKey? Within the 15.1 version, there's a "Delete All Rows" button that appears at the top buttonbar for lists in the UI.

Is that what you were looking for?

Regards,

Jon
 
Olivier responded:  2015-04-15 02:41
Hi Jon,

Thanks, we are not on 15.1 yet but will update soon. Is there a similar function for 14.3?

Regards,
Olivier
 
Jon (LabKey DevOps) responded:  2015-04-16 15:07
Hi Olivier,

There's a hacky way to pull this off in 14.3 using the XML Metadata below.

If you copied this in and changed the queryName to the name of the list, it would generate a button for you called Delete All Rows and that button would do the same job.

<tables xmlns="http://labkey.org/data/xml">
  <table tableName="ListName" tableDbType="NOT_IN_DB">
    <columns></columns>
    <buttonBarOptions position="top" includeStandardButtons="true" >
      <item text="Delete All Rows">
          <onClick>Ext4.Msg.confirm('Confirm Deletion', 'Are you sure you wish to delete all rows? This action cannot be undone.', function(button){if (button == 'yes'){var waitMask = Ext4.Msg.wait('Deleting Rows...', 'Delete Rows'); Ext4.Ajax.request({ url : LABKEY.ActionURL.buildURL('query', 'truncateTable'), method : 'POST', success: function(response) {waitMask.close(); var data = Ext4.JSON.decode(response.responseText); Ext4.Msg.show({ title : 'Success', buttons : Ext4.MessageBox.OK, msg : data.deletedRows + ' rows deleted', fn: function(btn) { if(btn == 'ok') { window.location.reload(); } } })}, failure : function(response, opts) { waitMask.close(); Ext4.getBody().unmask(); LABKEY.Utils.displayAjaxErrorResponse(response, opts); }, jsonData : {schemaName : 'lists', queryName : 'INSERTLISTNAMEHERE'}, scope : this });}});</onClick>
      </item>
    </buttonBarOptions>
  </table>
</tables>

Regards,

Jon