record_line_delete()
Remove one line item from a parent record.
Syntax
record_line_delete(table, recordId, subtable, lineId, opts?)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
table |
string or number | yes | The parent table's name, its database table name, or its numeric table id. |
recordId |
int | yes | The parent record's primary key. |
subtable |
string or number | yes | The line-item table to write. It must belong to this parent. |
lineId |
int | yes | The line's primary key. It must be a line of this record. In the visual builder this is {{line.id}} from a Get Related loop. |
opts |
array | no | Options. ["silent" => true] suppresses notifications to the record's followers. |
Returns
The parent record as it is after the write, in the same shape as record_get(). See record_line_add() for why the parent rather than the line.
Example
Drop any zero-quantity lines before sending an invoice:
$lines = records_related("invoices", $record["_meta"]["id"], "invoice_lines", "in");
foreach ($lines as $line) {
if ($line["qty"] == 0) {
$record = record_line_delete("invoices", $record["_meta"]["id"], "invoice_lines",
$line["_meta"]["id"]);
}
}
Example output
["id" => 42, "title" => "INV-1001", "price_total" => "75.00", "_meta" => ["id" => 42, "title" => "INV-1001"]]
Notes
- Only the line you name is removed. Every other line keeps its values and its id.
- Passing a line id that belongs to a different record throws, so a wrong id cannot delete somebody else's line.
- The parent's rollup totals recompute as part of the same write.
- Deleting the parent record removes all of its lines automatically; you do not need to clear them first.
- The write is recorded in the parent's activity history but does not trigger other automations.
See also: record_line_add(), record_line_update(), Sub-tables