Troubleshooting
Why a lot filter opens the wrong report template
Short answer
Selecting a lot in the filter changes only the archived data the report queries. The report-opening function accepts one template assigned in configuration, so every lot opens in the same layout. The fix is one report-opening function per product template; automated routing through an API lookup of the archived lot_type works only with explicit handling for failed, unknown or stale lookups.
On this page
- Why does the lot filter open the wrong report template?
- Is the data failing or only the template choice?
- Can a saved lot's lot_type be read into a runtime variable?
- Do temporary internal variables cover older lots?
- Which report-opening design should you deploy?
- What must the routing handle that the fixed functions do not?
- How do you test the routing with a real lot list?
- Questions asked
Selecting a lot in the filter changes which archived data the report shows, but it never changes the report template. The function that opens the report holds one template assigned in configuration, so lot1, lot2 and lot3 all open in the same layout even though each product has its own. The fix is structural: build one report-opening function per product template and point the operator to the matching one, or, if a single mixed lot list must pick its own report, read the lot's archived lot_type through the API and dispatch to the right function with explicit error handling. There is no native operation that copies an archived lot_type into a runtime variable, so the lookup is an integration you build, not a setting you enable.
Why does the lot filter open the wrong report template? #
The filter changes only which archived lot the report queries; the report-opening function keeps the one template assigned to it in configuration, so every lot you select opens in that same layout regardless of its product type.
Selecting historical data and selecting a report layout are two different operations that happen to share one button. The filter list drives the historian query: which lot record the report reads. The report-opening function drives the layout, and in this configuration it accepts exactly one template, set once when the function is defined. Changing the filter selection updates the query; nothing in that path reaches the template assignment.
That is why chasing the historian driver or the controller tags finds nothing. If every filter selection opens the same layout while the data inside it is correct, the cause is the fixed template assignment, and the fix lives in the report-opening layer, not in the data path.
Is the data failing or only the template choice? #
Open a known lot through the button that shows the lot filter list and compare two things: the lot identity displayed in the report and the template that actually opened. Each of four possible combinations points to a different fault.
- Correct lot, wrong template — the historical selection reaches the report, but the opening action loads the wrong layout. Inspect the template assigned to the report-opening function.
- Wrong lot, expected template — the layout is right; the selected-lot context is missing, stale or bound incorrectly. Trace the lot identifier from the filter into the report query.
- Wrong lot and wrong template — both the selection context and the template routing need work. Fix the lot binding first, then retest routing.
- Correct lot and correct template — this one selection works. Repeat with a lot from each of the other product types before declaring the system healthy.
A report that opens without an error has not necessarily opened correctly. A valid historical query can populate an unsuitable layout without raising anything, so check identity and layout on every open.
Can a saved lot's lot_type be read into a runtime variable? #
No native operation copies an archived field such as lot_type from a saved lot into a live runtime variable; displaying historical fields inside a report proves only that the field reaches the report, not that any variable holds it.
Your lot records carry lot_name, lot_type and lot_description. To route a report from lot_type you need an application-side lookup, and the platform's API is the route for it. The sequence:
- Read the selected lot's identifier from the filter context and confirm it uniquely identifies the intended archived record.
- Query that record's stored metadata through the platform's historical query interface and inspect the returned lot_type.
- Check whether the runtime accepts the result in an internal variable or another routing input your script can write.
- If it does, map the returned type to a report-opening function and dispatch; if it does not, stay with manual selection through separate functions.
Read the installed platform's API documentation for the exact query interface, returned fields and permitted variable-write mechanism for your build; this article does not name them. Keep the lookup inside the HMI and reporting application. Do not route the archived lot_type back into the controller to solve a report problem: a reporting fault does not require a PLC write.
Do temporary internal variables cover older lots? #
Retained internal variables preserve only the current or previous lot's context; one overwritten variable cannot represent lot1, lot2 and lot3 at the same time, so it cannot select the template for an arbitrary archived selection.
Run a two-reading test: take the selected archived lot's identity and the identity tied to the retained variable. If they differ, the variable is unsuitable for template selection, because a current product type or the previous lot's type will open a plausible but wrong report.
If retained values are to serve as a lookup at all, store them against a unique lot identifier and keep the association for the whole retention period. A runtime-only value disappears when the application restarts. For reports on any previously saved lot, retrieve the metadata from the persistent, lot-indexed store — the historian archive — instead of from an overwritten variable.
Which report-opening design should you deploy? #
Deploy one report-opening function per product template and let the operator pick the product-specific entry point; this uses template selection the platform already provides and removes any dependency on copying archived values into runtime variables.
The two designs, and what each costs:
- Separate functions for each template — the operator chooses the product-specific report path. No API work, no lookup latency; the interface must prevent or clearly flag an incompatible lot and function pairing.
- API lookup followed by explicit routing — needs the selected lot identifier and the returned lot_type. Automates a single mixed lot list, but adds the lookup, error handling and the dispatch logic, and it still ends by calling the per-template functions.
Retrieving lot_type alone does not make a fixed-template function dynamic. Whether the type arrives by operator choice or by API lookup, the dispatch to separate report-opening functions is what actually changes the layout.
What must the routing handle that the fixed functions do not? #
Automated routing must treat every failed or ambiguous lookup as a blocked open, never as a reason to fall back to a default layout; a wrong-but-plausible report is worse than a blocked one.
Handle these four outcomes separately:
- Missing metadata — the lot record exists but lot_type is empty. Block the open and show a selection error naming the lot.
- Unknown product type — lot_type is present but has no entry in the mapping. Block the open and show the unmapped value.
- Failed lookup — the API query returns no response or times out. Block the open; do not reuse anything from an earlier selection.
- Stale result — the operator changed the filter selection after the lookup ran. Invalidate the previous result before any open is allowed.
How do you test the routing with a real lot list? #
Test with the full lot list, one selection per product type, and confirm both the lot identity and the opened template on every open; with four lots over three templates, a fixed assignment leaves three of the four selections wrong.
Worked example. Suppose four archived lots over three product types:
| Lot | Archived lot_type | Correct template |
|---|---|---|
| lot1 | TYPE-A | report_A |
| lot2 | TYPE-B | report_B |
| lot3 | TYPE-C | report_C |
| lot4 | TYPE-B | report_B |
With the current fixed function, every selection opens report_A. lot1 is correct; lot2, lot3 and lot4 are wrong — 3 wrong selections out of 4 possible, or 75 percent of the lot list showing the wrong layout, with no error raised anywhere.
After adding one function per template, the test for each lot is: select it, confirm the filter shows that lot, confirm the mapped template opened, confirm the data shown belongs to that lot. For lot2 that means TYPE-B mapped to report_B and lot2's own values on the page. Then change the filter selection between opens and repeat, to prove the stale-result invalidation works. The routing passes only when identity and template are both right on all four selections.
The decision: if manual product choice is acceptable, build the separate functions and finish in configuration, with no API work. If a single mixed lot list must select its own report, build the API lookup of lot_type with the four blocked outcomes above, and validate the complete lookup-to-dispatch path on the full lot list before putting it in front of operators.
Questions asked
Can one combined template replace the three product templates?
Often, yes. If a single layout can render all three products by hiding the fields only some of them use, one fixed report-opening function serves every lot and the routing problem disappears. Choose this when the layouts differ only in a few optional fields; keep separate functions when the structures genuinely differ.
Where should the product-type-to-template mapping live?
In the HMI or reporting project, as a small lookup of product type to report-opening function. When a fourth product is added, you add one template, one function and one mapping row. Keeping the mapping in project configuration rather than buried in script logic keeps the routing auditable and easy to extend.
What happens to the routing after an application restart?
Anything held in runtime-only internal variables is lost, including any retained product type used for template selection. API-based routing is unaffected because every report open performs a fresh lookup of the selected lot. If you rely on retained variables for the most recent lot, re-read them or have the operator re-select after a restart before allowing report opens.
Does this fault affect the historian data itself?
No. The archived lot records, their type strings and the historical values are intact throughout; the fault is entirely in which layout the report-opening function loads. No migration, export or database change is needed to fix it, and the same wrong layout will appear on every client that uses that function.