cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jacktransform
Helper III
Helper III

Can't Patch Multiple Columns when Number Columns Null

Hi all!

 

I'm running into a problem with trying to update multiple columns in a record in one of my custom tables. My problem primarily involves 2 screens in my app.

 

Screen 1:

On screen 1 I have a gallery of existing records in my custom table. I click on a record in my custom table that I want to edit, and this sets a variable (varGUID) to the GUID of the record I have selected. This takes me to screen 2.

 

Screen 2:

On screen 2 I have an edit form full of all the columns in my custom entity with the Item set to a LookUp of the record I clicked on in the previous screen. Basically, I have all the data for the record I clicked on and the ability to edit all that record’s columns. The Item category for the edit form is like so:

 

LookUp([@'Custom Table'], 'Custom Table GUID' = varGUID)

 

In my custom table are multiple columns of differing data types. Specifically, there are multiple Text and Whole Number data type columns. Let's say that 'Column Text 1' and 'Column Text 2' are text type, and 'Column Num 1' and 'Column Num 2' are number type. The card values on the edit form for 'Column Text 1' and 'Column Text 2' are Text1CardValue and Text2CardValue respectively, while the card values for 'Column Num 1' and 'Column Num 2' are Num1CardValue and Num2CardValue respectively.

 

On screen 2 I have a save button to submit the changes to the columns in my custom table that I make. These changes are submitted through a patch like the one below:

 

Patch( [@'Custom Table'],

LookUp([@'Custom Table'], 'Custom Table GUID' = varGUID),

{

 ‘Column Text 1’: Text1CardValue.Text,

Column Text 2’: Text2CardValue.Text,

'Column Num 1': Value(Num1CardValue.Text),

'Column Num 2': Value(Num2CardValue.Text),

}

 

The problem is this only works if I have a value already saved in Microsoft Dataverse for ‘Column Num 1’ and ‘Column Num 2’, or you are patching in a value to BOTH of the number columns. So, if either ‘Column Num 1’ or ‘Column Num 2’ have no value already stored in Microsoft Dataverse and I am not patching in a value (ie. Num1CardValue or Num2CardValue are empty at the time of patching) then PowerApps will not update ANY of the columns values. If there are number values (even 0) stored in both ‘Column Num 1’ and ‘Column Num 2’ or the number columns are being patched with a number, then the patch executes perfectly and all column values (text and number type) are updated.

 

To further clarify, the example below would fail:

 

'Column Text 1' is currently null and is being patched with the value “Text 1”

'Column Text 2' is currently null and is being patched with the value “Text 2”

'Column Num 1' is currently null and is being patched with the value “123”

'Column Num 1' is currently null and is NOT being patched with anything (remaining null)

 

In the above scenario, the patch would NOT execute for ANY of the columns. All columns would remain null.

 

This issue is weird to me because the problem only comes from number type columns, not text type. The following example would actually succeed for all columns:

 

'Column Text 1' is currently null and is being patched with the value “Text 1”

'Column Text 2' is currently null and is NOT being patched with anything (remaining null)

'Column Num 1' is currently null and is being patched with the value “123”

'Column Num 1' is currently null and is being patched with the value “456”

 

I know this is long winded, but I’d really appreciate any help I can get. So far I have not found any way around this. If I want to patch all my columns I have to put in 0 for the number columns even when I’d prefer to leave them null.

 

Thanks to anyone who made it this far, and happy holidays!!

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @jacktransform ,

 

You could try to set a variable for each number column.

For example: If you have two numeric columns, you set two variables.

When the input is empty, the value of the variable is blank.

When the input is not empty, the value of the variable is the value of the input.

 

1\ Set the Onchange property of “Num1CardValue” to:

If(IsBlank(Num1CardValue.Text),Set(Var1,Blank()),Set(Var1,Value(Num1CardValue.Text)))

 

2\ Set the Onchange property of “Num2CardValue” to:

If(IsBlank(Num2CardValue.Text),Set(Var2,Blank()),Set(Var2,Value(Num2CardValue.Text)))

 

3\ Set the onselect property of the button to:

Patch('TEST 24S',First('TEST 24S'),{Name:"1",'Test 1':Text1CardValue.Text,'Test 2':Text2CardValue.Text,'Test 3':Var1,'Test 4':Var2})

 

In this way, your code will not be complicated and it will be dynamic.

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

View solution in original post

7 REPLIES 7
v-xiaochen-msft
Community Support
Community Support

Hi @jacktransform ,

 

Please check if the setting of your Whole Number column is "required". If so, please change the option to “optional” and save it.

v-xiaochen-msft_0-1608774257757.png

 

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

awerda
Resolver II
Resolver II

I would add as a note :

To decrease the number of lookups and increase performance you should

  • Replace varGuid with varRecord
  • Set(varRecord,ThisItem) (or gallery.selected)
  • Use varRecord as the item in the form
  • use varRecord in the Patch instead of the lookup, it will still work fine for the update.

-----------------------------------------------------------------------

Please if you find this helpful in anyway consider giving it kudos so others can benefit from it

jacktransform
Helper III
Helper III

@v-xiaochen-msft 

 

All of my whole number columns are already set to optional. Is there anything else that could be changed or is this a bug?

 

@awerda 

 

My app is actually a bit more complicated. My gallery that I am selecting from is made up a collection and not one single table. I'm not sure how I'd display a view form without using a LookUp.

 

Thank you both!

v-xiaochen-msft
Community Support
Community Support

Hi @jacktransform ,

 

I’m sorry , I may have misunderstood what you mean.

 

The point is if the textinput control has no value, then patch blank() function to number column.

It has prerequisites for use, you need to modify the settings.

 

You could try the following steps:

 

1\ Set up your canvas ( Open APP settings-> Advanced Settings-> Enable : Formula Level Error Management )

v-xiaochen-msft_0-1609217277820.png

 

 

2\ Please try to modify your code

If(

    IsBlank(Num1CardValue.Text) && (!IsBlank(Num2CardValue.Text)),

    Patch(

        'TEST 24S',

        First('TEST 24S'),

        {

            Name: "1",

            'Test 1': Text1CardValue.Text,

            'Test 2': Text2CardValue.Text,

            'Test 3': Blank(),

            'Test 4': Value(Num2CardValue.Text)

        }

    ),

    (!IsBlank(Num1CardValue.Text)) && IsBlank(Num2CardValue.Text),

    Patch(

        'TEST 24S',

        First('TEST 24S'),

        {

            Name: "1",

            'Test 1': Text1CardValue.Text,

            'Test 2': Text2CardValue.Text,

            'Test 3': Value(Num1CardValue.Text),

            'Test 4': Blank()

        }

    ),

    IsBlank(Num1CardValue.Text) && IsBlank(Num2CardValue.Text),

    Patch(

        'TEST 24S',

        First('TEST 24S'),

        {

            Name: "1",

            'Test 1': Text1CardValue.Text,

            'Test 2': Text2CardValue.Text,

            'Test 3': Blank(),

            'Test 4': Blank()

        }

    ),

    Patch(

        'TEST 24S',

        First('TEST 24S'),

        {

            Name: "1",

            'Test 1': Text1CardValue.Text,

            'Test 2': Text2CardValue.Text,

            'Test 3': Value(Num1CardValue.Text),

            'Test 4': Value(Num2CardValue.Text)

        }

    )

)

 

The following is the correspondence between my table, columns name and yours

'Custom Table' < > 'TEST 24S'

'Test 1' < > ‘Column Text 1’

'Test 2' < > ‘Column Text 2’

'Test 3' < > 'Column Num 1'

'Test 4' < > 'Column Num 2'

 

3\ The result is as follows:

FFF.gif

 

In addition, after you modify the setting and save it, you may need to restart the browser or wait for a while for the setting to take effect.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

@v-xiaochen-msft 

 

Thank you for the answer, I was afraid that would be the solution. It makes my app unnecessarily complex and adds way too much code. There's really no other solution? That solution is super inelegant when I have 5-10 number type columns that may or may not be null at the time of patching.

 

Thanks!

v-xiaochen-msft
Community Support
Community Support

Hi @jacktransform ,

 

You could try to set a variable for each number column.

For example: If you have two numeric columns, you set two variables.

When the input is empty, the value of the variable is blank.

When the input is not empty, the value of the variable is the value of the input.

 

1\ Set the Onchange property of “Num1CardValue” to:

If(IsBlank(Num1CardValue.Text),Set(Var1,Blank()),Set(Var1,Value(Num1CardValue.Text)))

 

2\ Set the Onchange property of “Num2CardValue” to:

If(IsBlank(Num2CardValue.Text),Set(Var2,Blank()),Set(Var2,Value(Num2CardValue.Text)))

 

3\ Set the onselect property of the button to:

Patch('TEST 24S',First('TEST 24S'),{Name:"1",'Test 1':Text1CardValue.Text,'Test 2':Text2CardValue.Text,'Test 3':Var1,'Test 4':Var2})

 

In this way, your code will not be complicated and it will be dynamic.

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

View solution in original post

jacktransform
Helper III
Helper III

@v-xiaochen-msft 

 

Thank you, I will try that soon and let you know how it works out!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Users online (58,994)