Tutorial: Updating Fields with the Run Button in a Grid Application

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

Creating a new button

1. Performing actions on multiple rows of a Grid application can be done creating a new button in the Grid.

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

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. In the code of our button we need some global variables, then, first, let’s create these variables accessing the onScriptInit event in the application menu…

…and use the code below

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

$vl_discount = {UnitPrice} - {UnitPrice}* 0.05; 
sc_exec_sql("UPDATE products SET TotalValue = $vl_discount WHERE ProductID = {ProductID}");

Event Button: OnFinish

[tot] = [arr_vl];

6. Access the menu “Layout >> Header and Footer” and enable the footer view, because we will use the application onFooter event.

7. Now let’s use the event onRecord of the application to change the color of the field

Event Grid: onRecord

if (in_array({ProductID}, $total, true)) { 
sc_field_style('TotalValue', '#FF0000'); 
sc_field_style('TotalValue', ''); 

8. And onFooter event of the application to clear the array.

Event Grid: onFooter

[tot]= array();

9. Now we must access the “Application >> Global Variables” menu to set [tot], [arr_vl] and [i] as variable “OUT”.

10. Run the application, select the records and click on the button “Discount”.

Tutorials in the same category

Analyical Chart

In this example we will see how to create an analytic chart using the Grid application. Creat...

Menu with Chart Applications

This example will use a menu treeview application to display the new charts generated by Scriptcase....

Using the Refined Filter

In this example we will develop a report using the refined filter option, which allows you to filter...

Percentage field

In this example we will see how to use the Percentage field available in the Grid. Configurin...

Comment this post