cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ElMeSaFeR
Helper IV
Helper IV

Patch multiple records - ComboBox included -

Hi,

 

I have a form with 2 modes (New, Edit)

this form contain many types of records ( Text, DatePicker, ListBox, ComboBox, DropDown, CheckBox  ) 

I include IF statement in my code If the form in New mode patch in new record - using Defaults - , and if the form in Edit mode to update the records based on a Gallery ID selection - Filter, First - . 

 

target DataBase is SQL

 

based on some previous posts here I can using ForAll Patch without Collection, but my issue is how to include ForAll with Patch function with multiple selections consideration ? 

 

Attachment file is an example for my form

 

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @ElMeSaFeR ,

You have not provided any code to work with, but if you are only patching one record, you can do something like this

   Patch(
      YourDataSourceName,
      If(
         YourFormName.Mode=FormMode.New,
         Defaults(YourDataSourceName),
         {ID:YourGalleryName.Selected.ID}
      ),
      {
         YourTextFieldName:YourTextBoxName.Text
         YourNumberFieldName:Value(YourNumberField.Selected.Value),
         YourDateFieldName:YourDatePickerName.SelectedDate
      }
   )
)

and you will get the idea for the rest.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hello @WarrenBelz 

Thanks for your fast response, your code is what exactly I use it in the app, and I explain it in my post also in same way

 

If (Form1.Mode = New ,
Set(
    NewRecord,
    Patch(
   '[dbo].[DBName]',
    Defaults('[dbo].[DBName]'),
        {

            

TextFieldName : InputText.Text,
NumberFieldName : Value(NumberField.Selected.Value),
DateFieldName : DatePickerName.SelectedDate


        }
        
    )
),Form1.Mode = Edit,


Set(
    EditRecord,
    Patch(
        '[dbo].[DBName]',
        First(
            Filter(
                '[dbo].[DBName]',
                ID = GalList.Selected.ID
            )
        ),
        {

            

TextFieldName : InputText.Text,
NumberFieldName : Value(NumberField.Selected.Value),
DateFieldName : DatePickerName.SelectedDate

        }
        
    )
)

 

I just want to include patching the ComboBox and ListBox patch in the code!

 

Thanks

 

Hi @ElMeSaFeR ,

Firstly, I have to assume a few things you have not told me, in particular what type of field you are Patching to in each case (Text, Numeric,. Boolean, Choice, Lookup, Date - I can guess a few) and whether any of the controls are multi-select. I have updated the code a little below, but the solution will depend on this information.

If(
   Form1.Mode = New,
   Set(
      NewRecord,
      Patch(
         '[dbo].[DBName]',
          Defaults('[dbo].[DBName]'),
         {
            TextFieldName : InputText.Text,
            NumberFieldName : Value(NumberField.Selected.Value),
            DateFieldName : DatePickerName.SelectedDate

         }
      )
   ),
   Form1.Mode = Edit,
   Set(
      EditRecord,
      Patch(
         '[dbo].[DBName]',
         {ID:GalList.Selected.ID},
         {
            TextFieldName : InputText.Text,
            NumberFieldName : Value(NumberField.Selected.Value),
            DateFieldName : DatePickerName.SelectedDate
            ListBoxFieldName: ListBoxName.Selected.Value
            ComboBoxFieldName:ComboBox.Selected.xxxx
         }
      )
   )
)

where xxxx depends on the Items property of the control.

When you type YourControlName.Selected. (note second dot), valid values will come up underneath. For some guidance of what they mean: -

  • If your Items are Choices(ListName.FieldName) - a Choices or Lookup field), the reference will be YourControlName.Selected.Value
  • If they are Distinct( . . .  .), it will be YourControlName.Selected.Result
  • The other option is when they are based on a field value in a list (other than Distinct), then it will be YourControlName.Selected.FieldName (actual field name)

There will be another answer if any are multi-select and this will also depend on the target field type.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

Hi @ElMeSaFeR ,
Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (4,166)