This new option in the Grid allows to create a button to delete records (checkbox)
Creating a new button
1. Performing actions on multiple rows of a Grid application can be done creating a new “Run” button in the Grid.
2.Enter the name of "Delete" .
3. This kind of button has 2 events to process PHP Codes.
onRecord: runs to each record that was selected.
onFinish: runs after process all selected records.
4. To do our application, first we will create some global variables in onInit event
Event Grid: OnInti
[i] = 0;
It will be our Array Key
[total_chked] = array();
Array where we will keep all selected values
5. Now we can use [i] and [total_chked] in the onRecord and onFinish of the Run button.
Event Button: Onrecord
Event Button: OnRecord
$arr=[i];
Keeping the key in a local variable
[total_chked][$arr]={ContactName};
Assigning the Contact Name to the Array
[i]++;
increasing the key to access the next Array position
sc_exec_sql("delete from customers where CustomerID = '{CustomerID}'");
sc_exec_sql ({field}/"sql command", "connection")
This macro allows to condition the circumstances in which the SQL commands are executed.
The "connection" parameter is optional. Required only, if the command is executed in a data base different from the application.
Event Button: OnFinish
Event Button: OnFinish
$tot = count([total_chked]);
Counting the total of checked records.
$contacts = $tot." Selected Contacts: ";
Will keep the message to be displayed
for($x=0;$x<$tot;$x++){
$contacts .= [total_chked][$x];
if($x == ($tot-1)){
$contacts .= ".";
}else{
$contacts .= ", ";
}
}
/* This code will check who is the last selected value to add a dot, else add a comma */