a

Updating Fields with the Run Button in a Grid Application

1. First we must select the fields that will be showed in the Grid..

   

2. Access “Grid>>Layout>>Header & Footer” and enable to display footer. (We will use the onFooter event)

   

3. Performing actions on multiple rows of a Grid application can be done creating a new “Run” button in the Grid.

Create new Button.

   

   

   

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. Before to create our Run button code, 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 [arr_vl] in onRecord and onFinish of the Run button.

   

Event Button: onRecord

$arr=[i];
[arr_vl][$arr]={ProductID};
[i]++;
$vl_discount = {UnitPrice} - {UnitPrice}* 0.05;
sc_exec_sql("UPDATE products SET TotalValue = $vl_discount WHERE ProductID = {ProductID}");

   

Event Button: OnFinish
[tot] = [arr_vl];

Grid Event

6. After create the button events we must use the events onRecord and onFooter of the application to change the field color and to clean the array.

   

Event Grid: onRecord

if(!empty([tot])){
$total=[tot];
if (in_array({ProductID}, $total, true)) {
sc_field_style('TotalValue', '#FF0000');
}else{
sc_field_style('TotalValue', '');
}
}

   

Event Grid: onFooter

[tot]= array();

7. Now we should access “Application>>Global Variables” to set [tot], [arr_vl] and [i] to be “OUT” variables.

   

Untitled Document

Rate this Tutorial
Bad Great
Leave your comments (optional).