record_line_update()

Change one line item on a parent record, leaving every other line untouched.

Syntax

record_line_update(table, recordId, subtable, lineId, row, 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.
row array yes Field values to change on that line.
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

Reprice every line on an invoice to the agreed rate:

$lines = records_related("invoices", $record["_meta"]["id"], "invoice_lines", "in");
foreach ($lines as $line) {
    if ($line["price"] != $record["agreed_price"]) {
        $record = record_line_update("invoices", $record["_meta"]["id"], "invoice_lines",
            $line["_meta"]["id"], ["price" => $record["agreed_price"]]);
    }
}
sys_log("Invoice now totals " . $record["price_total"]);

Example output

["id" => 42, "title" => "INV-1001", "price_total" => "150.00", "_meta" => ["id" => 42, "title" => "INV-1001"]]

Notes

  • Only the fields you pass are changed on that line; everything else stays as-is.
  • Lines you do not name keep their values and their ids. They are never rewritten.
  • Passing a line id that belongs to a different record throws, rather than moving the line.
  • The parent's rollup totals recompute as part of the same write.
  • The write is recorded in the parent's activity history but does not trigger other automations.

See also: record_line_add(), record_line_delete(), records_related(), Sub-tables