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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,718)