Run Button in a Grid Application (Processing Records)

This option in the Grid allows you to create a button to process a PHP code in the selected records (checkbox).

Creating a new button

1. You can perform actions on several rows of a Grid application by creating a new button in the Grid.

2. We will name the “Delete” field and select the type “Run“.

3. This type of button has 2 events to process PHP codes.

  • onRecord: Execute each record that was selected.
  • onFinish: Execute after processing all selected records.

4. In the code of our button, we need some global variables, then, first, we create these variables by accessing the onScriptInit event in the application menu …

… and use the following code

Event Grid: onScriptInit
[i] = 0;It will show an Array Key.
[total_chked] = array ()Array where we will save all the selected values.

5. Now we can use [i] and [total_chked] in onRecord and onFinish in the Run button.


//To delete the record uncomment the line below:
sc_exec_sql("delete from customers where CustomerID = '{CustomerID}'");
Button event: OnRecord
$ arr = [i];Keep the key in a local variable.
[total_chked] [$ arr] = {ContactName};Assign the contact name to the matrix
[i] ++;Increasing the key to access the next position of the Array.
$tb1 = "
<TABLE align='center' cellpadding='0' cellspacing='0'>
  <td style='padding: 0px' rowspan='2'><img src='../_lib/img/grp__NM__ico__NM__danger.png' style='border-width: 0px' align='top'></td>
  <TD align='center'>
   <table style='border-collapse: collapse; border-width: 0px'>
        <td style='padding: 0 7px; vertical-align: top; white-space: nowrap'>
</TABLE> <br>";

$tot = count([total_chked]);

$contacts = "";


 $contacts .= [total_chked][$x]."<br>"; 			


$tb2 = "<table cellpadding='4' cellspacing='2'>
         <td colspan='2' border='none'><strong> (".$tot.") ".{lang_customer_excluded}.": <strong></td>
        <td border='none'><font color='#003366'><strong>  ".$contacts." </strong></font> </td>         

echo $tb1.$tb2;
Button event: OnFinish
$ tot = count ([total_chked]);Counting the total verified records.
$ tot = count ([total_chked]); | Counting the total verified records.$ contacts = $ tot. “Selected Contacts:”; | 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 verify who is the last value selected to add a period, otherwise you will add a comma * / | | echo ”<table width = ‘300px’ border = ‘1’ bordercolor = ‘# 000000’ cellpadding = ‘0’ cellspacing = ‘0’>
Show the message with all contacts selected.
<td colspan = ‘2’> <strong> ($ tot) Selected contacts: <strong> </td>
<td> <font color = ‘# 003366’> < strong> $ contacts </strong> </font> </td>
</table> “; | |

6. Now we should access” Application >> Global variables “to set [i] and [total_chked] as “Output” variables

7. Running the application, select the records and click on the “Delete Records” button.

Tutorials in the same category

Tutorial: Saving Report Views

In this example, we will see the options available for the end user to store, in session or in a...

Tutorial: Grid with modal filter.

This tutorial will show how to configure a query filter to display in a modal window, using the res...

Export Option

To export different types of files we must carry out the following steps: 1 - Create a Grid ...

Integration with WhatsApp

To integrate WhatsApp with ScriptCase, we will be using a specific API called Chat-API, it is a...

Comment this post