Create or update a lab test result
distru-mutate-test-resultWriteCreates or updates one lab test result (a COA potency record) on a package or batch: its header and its cannabinoid and terpene values.
Inputs
Every tool also takes the common inputs.
| Field | Type | Required | Description |
|---|---|---|---|
| action | enumCREATEUPDATE | Yes | |
| id | string | No | Required for UPDATE. Resolve via distru-search-test-results. |
| packageId | string | No | CREATE only, or batchId: the package the result is uploaded to. Resolve via distru-search-packages. |
| batchId | string | No | CREATE only, or packageId: the batch the result is uploaded to. Resolve via distru-search-batches. |
| name | string | No | Required for CREATE. Without one from the user, the COA's sample or report ID; ask only if the COA has none. |
| labName | string or null | No | Send null to clear it. |
| labLicenseNumber | string or null | No | Send null to clear it. |
| releaseDate | string or null | No | YYYY-MM-DD. Send null to clear it. |
| mgUnit | enumMG_PER_GMG_PER_ML | No | What the mg fields are per. Required whenever an mg value is sent; must match the COA. |
| makePrimary | boolean | No | true makes it the primary result of the item it was uploaded to and the items that inherit it. On CREATE a result becomes primary anyway when the item has none. |
| values | object[] | No | Required for CREATE. Values to set; only cannabinoid and terpene fields are accepted. |
| values[]. | string | Yes | From testResultFields of distru-get-package / distru-get-batch (includeTestResultFields), e.g. thc_percentage, beta_myrcene_mg_per_unit. |
| values[]. | string or number or null | Yes | In the field's unit. |
Output
Presence on a nested field assumes its parent exists.
| Field | Type | Presence | Description |
|---|---|---|---|
| testResult | object | Always | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | string | Can be null | |
| testResult. | string | Can be null | |
| testResult. | string | Can be null | |
| testResult. | object | Can be null | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | string | Can be null | |
| testResult. | object | Can be null | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | object | Always | |
| testResult. | object[] | Always | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | object | Always | |
| testResult. | string | Always | |
| testResult. | number | Always | |
| testResult. | object[] | Always | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | string | Can be null | |
| testResult. | number | Always | |
| testResult. | object[] | Always | |
| testResult. | string | Always | |
| testResult. | string | Always | |
| testResult. | string | Can be null | "%", "mg/g" or "mg/mL". |
| testResult. | string | Always | Decimal string. |
What the AI reads
Creates or updates one lab test result (a COA potency record) on a package or batch: its header and its cannabinoid and terpene values. Before writing, read the results that already apply to the item (distru-search-test-results with packageIds / batchIds). If any does, list them plus "new result" and ask the user which to write to; never pick one yourself. Only fields turned on for the product category of the item a result is uploaded to are accepted. Read them with distru-get-package or distru-get-batch (includeTestResultFields): for CREATE on the item, for UPDATE on the package or batch of the result's search row, which may differ from the item the user named when the result is inherited. "Package or batch not found" also comes back for an inactive package or deleted batch, and on UPDATE when every item the result applies to is inactive or hidden from your teams. Write each value in the unit the COA states, a % value in its % field and an mg value in its mg field; never convert. Save a value the COA reports as ND or <LOQ as 0, and say so in your summary. Values that look misread are refused, naming the field: recheck the COA, never adjust a value to pass. Sparse update: on UPDATE only the fields and values passed change; one sent as null is cleared. A change shows on every package and batch the result applies to: after writing, summarize appliesTo, inactive items included. It lists the first 50 of each plus counts; say "and N more" past that. Results can't be deleted here; the user deletes one in Distru. Returns the result as distru-search-test-results does, plus appliesTo.