cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DGWolfe
Helper V
Helper V

Submitting collection to various forms using switch?

Hi All,

 

I have x3 inputs of user data (from Office365) and two text inputs that pre populate with SP choice column data based on Radio button choices.

 

All 5 inputs are then placed into a collection.

 

The collection is working fine:

 

ClearCollect(
    AckCollection,
    {
        col_ReviewYear: reviewyearTextInput.Text,
        col_AckType: AckTextInput.Text,
        col_Function: FunctionTextInput.Text,
        col_Department: DepartmentTextInput.Text,
        col_Name: nameComboBox.Selected.displayName,
        col_Role: roleComboBox.Selected.jobTitle,
        col_Email: emailComboBox.Selected.userPrincipalName,
        col_Date: DatePicker.SelectedDate
    }
)

What I am now running into trouble with is, I want to patch the collection to various lists based on the radio choice.

 

Eg.:

If Radio option 1 is chosen, patch to SP list 1

If Radio option 2 is chosen, patch to SP list 2

If Radio option 3 is chosen, patch to SP list 3

 

Can anyone assist please?

 

Thank you muchly.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @DGWolfe ,

Please trythis for the first item - note if you use this pattern (Patch the ForAll Table rather than ForAll loop the Patch) you will see significant performance improvements. ForAll creates a Table that can be patched in one action.

If(
   DepartmentRadio.Selected.Value = "Risk",
   Patch(
      'Acknowledgement Risk - PA',
      ForAll(
         AckCollection,
         {
            'Review Year': col_ReviewYear,
            'Acknowledgement Type': col_AckType,
            Function: col_Function,
            Department: col_Department,
            Name: col_Name,
            Role: col_Role,
            'u Number': col_Email,
            'Date Acknowledged': col_Date
         }
      )
   )
)

 

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.

Visit my blog Practical Power Apps

View solution in original post

11 REPLIES 11
v-xiaochen-msft
Community Support
Community Support

Hi @DGWolfe ,

 

We can use If() function something like:

If(Radio1.Selected.Value="first",Patch(First List,...),Radio1.Selected.Value="second",Patch(Second List,...))

 

Best Regards,

Wearsky

WarrenBelz
Super User
Super User

Hi @DGWolfe ,

Just a bit of hard coding

Switch(
   RadioName.Selected.Value,
   "Option1",
   Patch(
      SPList1,
      ForAll(
         AckCollection,
         {
            ReviewYear: colReviewYear,
            . . . . . .  .
         },
      )
   ),
   "Option2",
    Patch(
      SPList2,
      ForAll(
         AckColleciton,
         { . . . . 

 

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.

Visit my blog Practical Power Apps

Thanks, I tried that but it's not working.

@DGWolfe ,

Can you please share the code that is not working in Text - also what is not working (do you get errors or just no results?) I am assuming here you want new records in SharePoint.

Thanks @WarrenBelz , yes, trying for NEW data submission, not edit.

 

It's getting a lot red around the collection parameters.

 

I have tried a few different versions, but nothing.

 

this is what I currently have (just using one radio option to see if that would work before I plugged them all in)

 

If(

DepartmentRadio.Selected.Value,="Risk",
Patch(
        'Acknowledgement Risk - PA',AckCollection,
    {
        'Review Year': col_ReviewYear,
        'Acknowledgement Type': col_AckType,
        Function: col_Function,
        Department: col_Department,
        Name: col_Name,
         Role: col_Role,
        'u Number': col_Email,
       'Date Acknowledged': col_Date
    }
    )
)
v-xiaochen-msft
Community Support
Community Support

Hi @DGWolfe ,

 

Please try this:

If(

DepartmentRadio.Selected.Value="Risk",
ForAll(AckCollection,
Patch(
        'Acknowledgement Risk - PA',Defaults('Acknowledgement Risk - PA'),
    {
        'Review Year': col_ReviewYear,
        'Acknowledgement Type': col_AckType,
        Function: col_Function,
        Department: col_Department,
        Name: col_Name,
         Role: col_Role,
        'u Number': col_Email,
       'Date Acknowledged': col_Date
    }
    ))
)

 

Best Regards,

Wearsky

Hi @DGWolfe ,

Please trythis for the first item - note if you use this pattern (Patch the ForAll Table rather than ForAll loop the Patch) you will see significant performance improvements. ForAll creates a Table that can be patched in one action.

If(
   DepartmentRadio.Selected.Value = "Risk",
   Patch(
      'Acknowledgement Risk - PA',
      ForAll(
         AckCollection,
         {
            'Review Year': col_ReviewYear,
            'Acknowledgement Type': col_AckType,
            Function: col_Function,
            Department: col_Department,
            Name: col_Name,
            Role: col_Role,
            'u Number': col_Email,
            'Date Acknowledged': col_Date
         }
      )
   )
)

 

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.

Visit my blog Practical Power Apps

@WarrenBelz 

 

Still not working. I've tried that exact formula a few times (and even written it out). I keep getting "Invalid argument type (Table). Expecting a value instead

@DGWolfe ,

Which field (I simply copied your code) ? Can you please list the field types of all the items patched.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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