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:
- Add Tags to UNS (Tutorial) - uses TankFarm tags
In this page:
Step 1: Create a Simple Text Report
We'll create a shift report showing tank status.
- Navigate to Reports → Forms
- Click first row to add new form
- Configure:
- Name:
ShiftReport
- SaveFormat:
Text
- SaveFileName:
C:\Reports\Shift_{Info.Date}.txt
- Name:
- Click OK
Step 2: Design Report Content
- Go to Reports → Forms Editor
- Select
ShiftReport
from dropdown - 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
- Save the form (Ctrl+S)
Step 3: Test Report Generation
- Start runtime (F5)
- Open Scripts → Tasks
- 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);
}
- Run script
- Check
C:\Reports\
for generated text file
Step 4: Create WebData for API
Now we'll send tank data to an external system.
- Navigate to Reports → WebData
- Click Plus to add
- Configure:
- Name:
TankDataAPI
- Encoding:
JSON
- DefaultURL:
https://api.example.com/tankdata
- Name:
- Click OK
Step 5: Configure JSON Structure
- Go to Reports → WebData Editor
- Select
TankDataAPI
- 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}
}
}
- Save the WebData
Step 6: Test Data Exchange
- 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");
}
- Run script
- Open saved JSON file to verify structure
Step 7: Schedule Automatic Reports
Create scheduled task for shift reports:
- Go to Scripts → Tasks
- Create new task:
ShiftReportSchedule
- Set trigger:
Server.Hour
- 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:
- Open Displays → MainPage
- Add Button control:
- Text: "View Shift Report"
- Name:
btnViewReport
- 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
- During runtime, open Reports → Monitor
- Verify report status:
- Name: ShiftReport
- LastStatus: Success
- SavedFileName: Shows generated file path
- Check for any errors in LastStatusMessage
Step 10: Test Complete Workflow
- Start runtime (F5)
- Let tags update with live values
- Wait for scheduled generation OR
- Manually trigger:
@Report.Form.ShiftReport.Save()
- Click "View Shift Report" button
- 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...