Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Mass Deletion

Questions related to using nuBuilder Forte.
Post Reply
redmonk
Posts: 11
Joined: Sun Feb 04, 2018 7:18 am

Mass Deletion

Unread post by redmonk »

Any pointers on how to add Browse Action Button that can delete all selected records (based on search)
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Mass Deletion

Unread post 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.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Mass Deletion

Unread post 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
Post Reply