From 492f89b2c4491c6bdc54c6e2495534924dcd1b35 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Wed, 9 Sep 2026 05:53:53 -0600 Subject: [PATCH] Bound the arrival acquisition type lookup to one row An animal with more than one arrival record made getObject() throw, so the status recalc failed for any rearrived animal, including when entering its death. --- ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java b/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java index 35f61d29c..b2b6013dc 100644 --- a/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java +++ b/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java @@ -41,6 +41,7 @@ import org.labkey.api.data.SQLFragment; import org.labkey.api.data.Selector; import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; import org.labkey.api.data.SqlExecutor; import org.labkey.api.data.SqlSelector; import org.labkey.api.data.Table; @@ -1781,7 +1782,9 @@ public void updateStatusField(List ids, Map> liveBirt ColumnInfo acquisitionColumn = columns.get(acquisitionFieldKey); if (acquisitionColumn != null) { - TableSelector ts = new TableSelector(arrivalTable, Collections.singleton(acquisitionColumn), new SimpleFilter(FieldKey.fromParts("Id"), id), null); + // In some cases, an animal can arrive more than once, so bound this to one row: unbounded, getObject() + // throws on the extra rows rather than picking one. Sort so the row picked is the latest arrival, not arbitrary. + TableSelector ts = new TableSelector(arrivalTable, Collections.singleton(acquisitionColumn), new SimpleFilter(FieldKey.fromParts("Id"), id), new Sort("-date")).setMaxRows(1); acquitype = ts.getObject(String.class); } }