4 min readRishi

Patch in Canvas Apps: The Blank Column That Overwrites a Real Value

Patch in Canvas Apps: The Blank Column That Overwrites a Real Value

Patch does not mean "save what changed." It means "write this record onto that row." Every column present in the change record is written. A column whose value is blank is cleared. Canvas apps hit this when a form's Updates record, or a variable that was never set, is passed through and a note, a lookup, or a status the user never touched comes back empty.

This is not a Dataverse quirk. SharePoint and SQL connectors do the same thing: a property that is present and blank is an instruction to clear.

What actually gets written

The second argument is the row to change. The third argument, and any further ones, are merged and applied. Columns you leave out of those records stay as they are. Columns you set are replaced, and Blank() is a value.

Patch(
    Orders,
    LookUp(Orders, OrderId = selectedId),
    { Status: statusDropdown.Selected.Value },
    If(!IsBlank(noteInput.Text), { Note: noteInput.Text })
)

Status is always written. Note is written only when the input has text, because a false If returns blank and that argument adds no columns. The version that clears notes is the one that always passes the input:

Patch(
    Orders,
    LookUp(Orders, OrderId = selectedId),
    { Status: statusDropdown.Selected.Value, Note: noteInput.Text }
)

An empty text input is blank. The column is present. The stored note is gone. The same thing happens with a lookup dropdown that has no selection, and with a form card the user never opened.

EditForm.Updates includes every card's Update property, not the cards the user edited. An empty card contributes a blank column, and Patch applies it. That is why "I only changed Status" still wipes Notes.

Build a change record, not a full row

When the screen has a handful of controls, name the columns:

With(
    {
        change:
            { Status: statusDropdown.Selected.Value } &
            If(!IsBlank(noteInput.Text), { Note: noteInput.Text }, {}) &
            If(!IsBlank(ownerCombo.Selected), { Owner: ownerCombo.Selected }, {})
    },
    Patch(Orders, LookUp(Orders, OrderId = selectedId), change)
)

{} adds no columns. A record with Owner: Blank() adds Owner and clears it. Those are different. If the user has a Clear button, that button should pass Blank() on purpose. An empty combo on load should not.

If you must use a form, do not Patch(..., Form.Updates) for a partial edit. Either:

  • Submit the form with SubmitForm and accept that every card writes, and hide or disable cards you do not want cleared, or
  • Build the change record from Form.Updates by dropping blanks: only include a column when the card was visible and the user touched it. There is no built-in "dirty columns" collection. You keep that yourself (UpdateContext({ noteDirty: true }) on the input's OnChange).

The base record has to be a row

LookUp that finds nothing returns blank. A blank base is not an update of the row you meant. Check it and stop.

With(
    { row: LookUp(Orders, OrderId = selectedId) },
    If(
        IsBlank(row),
        Notify("Order not found", NotificationType.Error),
        Patch(Orders, row, change)
    )
)

Creating is a different call: the base record is Defaults(Orders), and you pass the columns for the new row. Using Defaults because the lookup failed is how a double-click creates a second order.

Do not pass Gallery.Selected as the change record. It contains every column the gallery loaded, plus blanks for columns it did not. You will write those blanks, and you can write system columns you had no reason to touch. Name the columns.

LookUp on the primary key is a delegable predicate on Dataverse, so the base row does not require pulling the table into a collection. The delegation rules for everything else you filter are in delegation warnings. Patch itself is not a query. It will happily write a blank that a non-delegable filter hid from the gallery.

Dataverse versus SharePoint

On Dataverse, clearing a required column fails the Patch and Errors will tell you. That is noisy but safe. On SharePoint, many columns are not required. The clear succeeds. The next person to open the item finds an empty Title or a missing Person field.

Person and lookup columns are the usual casualties: a combo that has not loaded its default looks blank, and Patch writes blank. Wait for combo.Selected to be populated, or omit the column until combo.Selected is not blank and the user changed it.

A practical rule

Build the change record from controls the user can see on this screen, and omit a column when the control is empty and empty means "leave it alone." If empty means "clear it," pass Blank() on purpose, from a button that says clear. Those are different operations. A single Patch of Form.Updates treats them as the same operation, and the next person to open the record finds out which one you shipped.

Keep reading

Newsletter

New posts, straight to your inbox

One email when a new post goes up. Double opt-in, unsubscribe anytime. Not a daily digest.

Comments

  • No comments yet. Be the first.