# Syntax & Functions Cookbook

This page complements the [Syntax & Functions reference](/user-documentation/build/building-the-reporting/syntax-functions.md) with complete, ready-to-adapt report templates for common field operations scenarios.

## Recipe 1 — Per-submission inspection report (Word)

**Use case:** Generate one formatted Word document per intervention submission, including the inspector's details, GPS location, photos with GPS watermarks, and a conditional defect section.

### Template structure

```
<%Inspector.FullName%> — <%F('dd/MM/yyyy', InspectionDate)%>

Site: <%List(', ', SiteAddress, PostalCode, City)%>
Status: <%If(InspectionResult = 'Compliant', 'COMPLIANT ✓', 'NON-COMPLIANT ✗')%>

<%Map(SubmissionLatitude, SubmissionLongitude, 15, 400, 250, 0)%>
```

Photos (with GPS coordinates as watermark):

```
<%Images(Photos)%><%ImageWatermark(200, 0,
  List(' | ',
    ImageExif(Photos, 'GpsLatitudeDM'),
    ImageExif(Photos, 'GpsLongitudeDM'),
    ImageExif(Photos, 'DateTime')
  ), 'Left', 'Bottom', 'White', '#000000', 0.5, 11)%>
```

Conditional defect section (hidden when no defects):

```
<%Display(DefectCount > 0)%>
## Defects observed

<%Relation('Defects', 'DefectDate')%>
  <%DefectDescription%> — <%F('dd/MM/yyyy', DefectDate)%>
<%End%>
```

Signature:

```
<%Image(InspectorSignature, 120)%>
```

### Key functions used

* `List()` — combines address fields, omitting empty ones
* `If()` — renders a human-readable status
* `Map()` — shows the intervention GPS position
* `Images()` + `ImageWatermark()` + `ImageExif()` — photos stamped with GPS and date
* `Display()` / `End` — hides the defect section when there are none
* `Relation()` — lists related defect records

***

## Recipe 2 — Monthly summary listing report (Excel)

**Use case:** An Excel listing report sent by email every month, covering all submissions from the previous month, with a count, total, and bar chart.

### PPActions sheet

| Type:table ; TableName:Interventions ; Value:Id | Type:table ; TableName:Interventions ; Value:TechnicianName | Type:table ; TableName:Interventions ; Value:InterventionDate | Type:table ; TableName:Interventions ; Value:Duration |
| ----------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------- |

### Data sheet (Interventions table — one row template)

| #              | Technician                 | Date                                          | Duration (min)          |
| -------------- | -------------------------- | --------------------------------------------- | ----------------------- |
| `<%Value:Id%>` | `<%Value:TechnicianName%>` | `<%Value:F('dd/MM/yyyy', InterventionDate)%>` | `<%Value:N(Duration)%>` |

### Summary section (below the table)

```
Total interventions:   <%Count()%>
Total duration (min):  <%Sum('N(Duration)')%>
Average (min):         <%Avg('N(Duration)')%>
```

Chart (bar chart of interventions by technician):

```
<%Chart('Bar', 'Count()', 'TechnicianName', true, 500, 300)%>
```

### Listing mode filter (Repeat in PPActions)

```
<%Repeat(InterventionDate > #date-1m# AND InterventionDate < #date#, InterventionDate)%>
```

### Key functions used

* `N()` / `Sum()` / `Avg()` / `Count()` — aggregation over the full dataset
* `Chart()` — bar chart by technician
* `Repeat()` with date filter — limits to the previous month
* `F()` — date formatting in the table

***

## Recipe 3 — Delivery note with related line items (Word)

**Use case:** A delivery note per submission, listing the ordered products from a relationship field, with a line count and totals.

### Main submission section

```
Delivery note #<%SubmissionId%>
Date: <%F('dd/MM/yyyy', DeliveryDate)%>
Client: <%ClientName%>
Address: <%List(', ', DeliveryAddress, PostalCode, City)%>
```

### Relation table (one row per product)

Place `Relation()` in the first cell of a table row:

```
<%Relation('OrderedProducts', 'ProductName')%>
```

Row template:

| `<%ProductName%>` | `<%ProductReference%>` | `<%Quantity%>` | `<%F('0.00', UnitPrice)%>` | `<%F('0.00', Quantity * UnitPrice)%>` |
| ----------------- | ---------------------- | -------------- | -------------------------- | ------------------------------------- |

Footer row (below the relation table):

```
<%[OrderedProducts.Count]%> items — Total: <%Sum('N(Quantity) * N(UnitPrice)')%> €
```

### Key functions used

* `Relation()` — one row per linked product submission
* `[Relation.Count]` — total number of product lines
* `List()` — formatted delivery address
* Arithmetic in tags — `Quantity * UnitPrice`
* `Sum()` — grand total across all product lines

***

## Recipe 4 — Conditional multi-section report (Word)

**Use case:** A single template that adapts its content based on the value of a list field (e.g. `InterventionType`). Each section is only rendered for the relevant intervention type.

### Pattern

```
<%Display(InterventionType = 'Maintenance')%>
## Maintenance checklist
<%ChecklistItem1%> — <%If(ChecklistItem1Result = 'OK', 'Pass', 'Fail')%>
<%ChecklistItem2%> — <%If(ChecklistItem2Result = 'OK', 'Pass', 'Fail')%>
<%End%>

<%Display(InterventionType = 'Installation')%>
## Installation record
Date installed: <%F('dd/MM/yyyy', InstallationDate)%>
Installed by: <%Technician.FullName%>
Serial number: <%SerialNumber%>
<%End%>

<%Display(InterventionType = 'Audit')%>
## Audit findings
Score: <%AuditScore%> / 100
<%If(AuditScore >= 80, 'Result: SATISFACTORY', 'Result: ACTION REQUIRED')%>
<%End%>
```

### Key functions used

* `Display()` / `End` — shows each section only for the matching type
* `If()` — renders pass/fail and result labels
* `F()` — date formatting

***

## Tips for all recipes

* **Test with real data.** Generate a report from a submission that has edge cases (empty optional fields, maximum photo count) before finalising.
* **Use `Exists()` to guard image fields.** If a photo may be absent, wrap the tag: `<%If(Exists('Photos#1'), Image([Photos#1], 200), '')%>` to avoid a blank space in the output.
* **Listing mode limit.** Excel and scheduled Word reports are capped at 30,000 submissions. Add a `Repeat()` date filter to keep generation times reasonable.
* **Apostrophes.** When building templates in PowerPoint, replace smart quotes (`'`) with straight ones (`'`) before saving — see the [PowerPoint page](/user-documentation/build/building-the-reporting/report-templates/ppt.md) for details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.center.daxium-air.com/user-documentation/build/building-the-reporting/syntax-functions-cookbook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
