Start a conversation

Selecting records and generating PDF

Today you will understand how to select records from a grid application and generate a Report PDF for each one selected.


You'll need to configure two applications: grid and report pdf. See how below. Links for support: sc_redir macro, Selecting records from a Grid using the Run button


  1. Grid application settings
  2. Creating a RUN button
  3. Managing the RUN button
  4. Managing PDF Report application

GRID APPLICATION SETTINGS

1- Create a new grid application with your database tables.

2- In Events, select OnScriptInit and type this line of code.

[i] = 0;
[total_checked] = array();

CREATING A RUN BUTTON

1- In your grid application, go to Buttons —> New button

2- Select this button as a RUN button


3- Manage the button the way you want it and at Target you choose Open in the same window



MANAGING THE RUN BUTTON

1- In your button, at OnRecord event, type this line of code.

$arr = [i];
[total_checked][$arr] = {customerid};
[i]++;

The variable [total_checked] will be responsible to get how many records were checked to generate a report PDF. {customerid} it is the field that we're using as a key and parameter to locate records of customers table.

2- At OnFinish event, in the same button, we'll do a simple verification of what records were checked and redirect to PDF Report using this customer string field as a parameter with sc_redir macro

$tot = count([total_checked]); 
$customers = "";



for($x=0;$x<$tot;$x++){
    $customers .= "'";
    $customers .= [total_checked][$x];
    $customers .= "'";
    
    if($x != ($tot-1)){
    $customers .=",";
    
    }
    
    }

[glo_customers] = $customers;

 echo "(".$tot.") Clientes selecionados:  ".$customers;
sc_redir(pdfreport_customers, parm1=[glo_customers],"_blank");

3- Finally, go to Application —> Global variable. You need to define all created variables as a output data


MANAGING PDF REPORT APPLICATION

1- Create a new PDF Report application, using the same database table that you've used in grid application

2- In PDF Report, we'll only need to change his SQL settings to receive data from your grid application then generating PDF of each data

Let's put a Where clause attaching "customerid" field with a global variable using "IN"

WHERE 
customerid IN ([glo_customers])

Finished all settings, your grid application must be working correctly to generate PDF report of each record selected. See how this works in this video: https://youtu.be/9OcZ_EFq8eo

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Iago Chaves

  2. Posted
  3. Updated

Comments