Home » Patch a NULL value

Patch a NULL value

Patching a NULL value in PowerApps seems to be a fraught business. There are countless people wanting to patch NULL values, and yet Microsoft’s own documentation falls short.

However, it’s quite simple to patch a NULL value – i.e. insert a NULL value into a data source – with a couple of simple steps.

Insert a NULL value into PowerApps data source

The first thing to do is to go into the File menu, where you’ll find all the PowerApps’ settings.

Screenshot of PowerApps settings screen
PowerApps settings screen

Then click or tap on ‘Advanced settings’ (you’ll see it highlighted in the screenshot above, as my mouse is hovering over it).

Then, you’ll see the list of Advanced settings. Scroll down to ‘Formula-level error management’.

Screenshot of PowerApps Advanced settings screen
PowerApps Advanced settings
Screenshot of some of the advanced settings in a PowerApp
Scroll down to here. Enable the error management by clicking or tapping on the ‘switch’.

I don’t really know why you need to turn on error handling, because Microsoft’s explanation was a bit flaky and I’m still learning. But you need to do this first.

Do that Patch

Now when you add a Patch command to button or other element on the screen, you can set it to patch an empty string by using double quotes: “”. This has worked for me on columns in my SQL Server database whatever the format. I’ve even been able to patch NULL values into date columns, which seemed particularly tricky.

So now, when your user has mistakenly added some data in, but wants to clear a field, you can let them do that. For example, in my app a person might record when they finished a task. Then, if they realise that they ‘finished’ the wrong task, they’d need to keep the task record, but empty the ‘TaskFinished’ column.

You can also, if you’re using an If statement, simply leave the ‘false’ case blank, as in:

If(SomeVariable = 20, Patch(...) )

Notice there’s no ‘false’ code to run. We just don’t Patch anything – or rather we Patch ‘nothing’.

You can code a normal NULL Patch like this:

Patch('[dbo].[TaskList]', First(Filter('[dbo].[TaskList]',
   TaskNo = Dropdown1.Selected.Value)),
   {
      Notes: TextInput1.Text,
      DateFinished: ""
   }
)

That works for Numeric fields. For text fields you might be better off using the Blank() function to replace that “”. So it would look like this:

Patch('[dbo].[TaskList]', First(Filter('[dbo].[TaskList]',
   TaskNo = Dropdown1.Selected.Value)),
   {
      Notes: TextInput1.Text,
      DateFinished: Blank()
   }
)

3 comments

  1. Andy says:

    Thanks for the article. I can’t believe this feature is still in preview..Also I note that when patching an integer in SQL the Blank() didnt work but “” did, and yet with a string Blank() works. Very strange..

    • Moondog says:

      Yes, I’m still learning to try both Blank() and “” if the first one doesn’t work! PowerApps is changing all the time, so I always blame that instead of my forgetfulness, and remain hopeful that things will settle down and constantly improve.

      Martin

Leave a Reply

Your email address will not be published. Required fields are marked *