Reports Generation (Tutorial) teaches you to:

  • Create text reports with real-time data
  • Exchange information with external systems using WebData.
  • Set up notifications
  • Enable audit trail for FDA 21 CFR Part 11 compliance

Prerequisites:

In this page:




Reports → Tutorial | Concept | How-to Guide | Reference



Step 1: Create a Simple Text Report

We'll create a shift report showing tank status.

  1. Navigate to Reports → Forms
  2. Click first row to add new form
  3. Configure:
    • Name: ShiftReport
    • SaveFormat: Text
    • SaveFileName: C:\Reports\Shift_{Info.Date}.txt
  4. Click OK

Step 2: Design Report Content

  1. Go to Reports → Forms Editor
  2. Select ShiftReport from dropdown
  3. Enter this report template:
================================
    TANK FARM SHIFT REPORT
    Date: {Info.Date}
    Time: {Info.Time}
    Operator: {Client.UserName}
================================

TANK STATUS SUMMARY
-------------------
Tank 1:
  Level: {Tag.TankFarm/Tank1/Level} ft
  Temperature: {Tag.TankFarm/Tank1/Temp} °F
  Pressure: {Tag.TankFarm/Tank1/Pressure} PSI
  Status: {Tag.TankFarm/Tank1/Status}

Tank 2:
  Level: {Tag.TankFarm/Tank2/Level} ft
  Temperature: {Tag.TankFarm/Tank2/Temp} °F
  Pressure: {Tag.TankFarm/Tank2/Pressure} PSI
  Status: {Tag.TankFarm/Tank2/Status}

PRODUCTION METRICS
------------------
Total Volume: {Tag.TankFarm/Metrics/TotalVolume} gal
Flow Rate: {Tag.TankFarm/Metrics/FlowRate} gpm
Daily Production: {Tag.TankFarm/Metrics/DailyProduction} gal

================================
End of Report
  1. Save the form (Ctrl+S)

Step 3: Test Report Generation

  1. Start runtime (F5)
  2. Open Scripts → Tasks
  3. Create test script:

csharp

public void TestReport()
{
    // Set some test values
    @Tag.TankFarm/Tank1/Level = 75.5;
    @Tag.TankFarm/Tank1/Temp = 68.2;
    @Tag.TankFarm/Tank1/Pressure = 14.7;
    @Tag.TankFarm/Tank1/Status = "Normal";
    
    // Generate report
    @Report.Form.ShiftReport.Save();
    
    // Show confirmation
    @Info.Trace("Report saved to: " + 
                 @Report.Form.ShiftReport.SavedFileName);
}
  1. Run script
  2. Check C:\Reports\ for generated text file

Step 4: Create WebData for API

Now we'll send tank data to an external system.

  1. Navigate to Reports → WebData
  2. Click Plus to add
  3. Configure:
  4. Click OK

Step 5: Configure JSON Structure

  1. Go to Reports → WebData Editor
  2. Select TankDataAPI
  3. Enter JSON template:

json

{
  "timestamp": "{Info.Date} {Info.Time}",
  "facility": "TankFarm-01",
  "tanks": [
    {
      "id": "Tank1",
      "level": {Tag.TankFarm/Tank1/Level},
      "temperature": {Tag.TankFarm/Tank1/Temp},
      "pressure": {Tag.TankFarm/Tank1/Pressure},
      "status": "{Tag.TankFarm/Tank1/Status}"
    },
    {
      "id": "Tank2", 
      "level": {Tag.TankFarm/Tank2/Level},
      "temperature": {Tag.TankFarm/Tank2/Temp},
      "pressure": {Tag.TankFarm/Tank2/Pressure},
      "status": "{Tag.TankFarm/Tank2/Status}"
    }
  ],
  "metrics": {
    "totalVolume": {Tag.TankFarm/Metrics/TotalVolume},
    "flowRate": {Tag.TankFarm/Metrics/FlowRate}
  }
}
  1. Save the WebData

Step 6: Test Data Exchange

  1. Create script to test WebData:

csharp

public async void SendTankData()
{
    // For testing, save to file instead of API
    @Report.WebData.TankDataAPI.SaveFileName = 
        @"C:\Reports\TankData.json";
    
    // Save JSON with current tag values
    @Report.WebData.TankDataAPI.Save();
    
    @Info.Trace("JSON data saved");
}
  1. Run script
  2. Open saved JSON file to verify structure

Step 7: Schedule Automatic Reports

Create scheduled task for shift reports:

  1. Go to Scripts → Tasks
  2. Create new task: ShiftReportSchedule
  3. Set trigger: Server.Hour
  4. Add code:

csharp

public void GenerateShiftReport()
{
    // Generate at 6:00, 14:00, 22:00 (shift changes)
    if (@Server.Hour == 6 || @Server.Hour == 14 || @Server.Hour == 22)
    {
        // Calculate shift metrics
        @Tag.TankFarm/Metrics/DailyProduction = 
            @Tag.TankFarm/Tank1/Level * 1000 + 
            @Tag.TankFarm/Tank2/Level * 1000;
        
        // Generate report
        @Report.Form.ShiftReport.Save();
        
        // Log generation
        @Alarm.AuditTrail.AddCustomMessage(
            "Shift report generated", null, null, null, null, null, null);
    }
}

Step 8: Add Report Viewer

Display the generated report:

  1. Open Displays → MainPage
  2. Add Button control:
    • Text: "View Shift Report"
    • Name: btnViewReport
  3. Double-click button for code:

csharp

public void btnViewReport_Click(object sender, EventArgs e)
{
    // Open report in default text editor
    string reportPath = @Report.Form.ShiftReport.SavedFileName;
    
    if (System.IO.File.Exists(reportPath))
    {
        System.Diagnostics.Process.Start(reportPath);
    }
    else
    {
        MessageBox.Show("No report found. Generate one first.");
    }
}

Step 9: Monitor Report Status

  1. During runtime, open Reports → Monitor
  2. Verify report status:
    • Name: ShiftReport
    • LastStatus: Success
    • SavedFileName: Shows generated file path
  3. Check for any errors in LastStatusMessage

Step 10: Test Complete Workflow

  1. Start runtime (F5)
  2. Let tags update with live values
  3. Wait for scheduled generation OR
  4. Manually trigger: @Report.Form.ShiftReport.Save()
  5. Click "View Shift Report" button
  6. Verify report contains current data

Next Steps

  • [Forms Editor] - Add tables and charts
  • [WebData POST] - Send data to real APIs
  • [PDF Reports] - Professional formatted output
This tutorial provides a simple introduction to Reports, building on the existing tank farm tags while keeping complexity low. Students can see immediate results with text reports and understand the JSON structure for data exchange.

In this section...