Page 1 of 1

Mass Deletion

Posted: Mon Mar 12, 2018 1:16 pm
by redmonk
Any pointers on how to add Browse Action Button that can delete all selected records (based on search)

Re: Mass Deletion

Posted: Tue Mar 13, 2018 1:35 pm
by toms
Something like this could work:

Set a Hash Cookie like:

Code: Select all

nuSetProperty('browsesql', nuCurrentProperties().browse_sql);
Use nuRunPHPHidden() to run a PHP procedure.

This PHP Procedure would then run a query to retrieve the primary keys of the (filtered rows)

Code: Select all

$s = "#browsesql#";
$t = nuRunQuery($s);
...
...
Next, you would have to build a delete statement to delete all rows that match these primary keys.

I know it may be a bit abstract, but it should work that way.

Re: Mass Deletion

Posted: Wed Mar 14, 2018 3:24 am
by admin
redmonk,

You could give this a go.


Add this to the Javascript of the Form...

Code: Select all


nuAddActionButton('deleteGroup', 'Delete Unfiltered Records', 'deleteWhere()');

function deleteWhere(){

    if (confirm("Are you sure you want to delete all unfiltered records?")){
            
        nuSetProperty('deleteFiltered', '1');
        $('#nuSearchButton').click();
        nuSetProperty('deleteFiltered', '0');
        
    }
    
}

And add this to Before Browse...

Code: Select all


if(nuHash()['deleteFiltered'] == '1'){
    
    $sql    = nuHash()['browse_sql'];
    $w      = strpos($sql, 'WHERE');
    $o      = strpos($sql, 'ORDER BY');
    $o      = !$o ? 10000 : $o;
    $s      = substr($sql, $w, $o - $w);
    $s      = str_replace('\\', '', $s);

    nuRunQuery('DELETE FROM theteblename ' . $s);

}


Steven