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

Patch checkbox selections in a ForAll loop to Sharepoint

Hello PA community!

 

I have a tough one to solve here, hoping you can help me out.

 

1- I have a gallery of item that I can select with a checkbox

2- When I select one, it create a global variable like: set(variable, thisitem)

3- When I uncheck, it puts the variable back to blank

 

The issue 1:

I can only patch one single item to SharePoint and I would like to be able to select multiple items from the gallery, somehow amend the global variable, put it all in a ForAll loop with the same patching command.

 

The issue 2:

When I select a second item it overwrites the global variable (obviously) and if I deselect it, it put it back to blank even if the previous item is ticked (obviously).

 

Here's the code for the patching command:

Patch(
    'Desk Reservations',
    Defaults('Desk Reservations'),
    {
        Title: currentUser.FullName & " " & selectedDesk.Title,
        DeskText: selectedDesk.Title,
        'Check In': startTime,
        'Check Out': endTime,
        'Reserved By': {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & currentUser.Email,
            Department: "",
            DisplayName: currentUser.FullName,
            Email: currentUser.Email,
            JobTitle: "",
            Picture: ""
        }
    }
);Navigate(Success)

 

If you already have a way around this, I'd be happy to hear about it!

 

Cheers

Anthony

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @AnthonyRegnier ,

Do you want to use multiple selected items in a gallery to update a sharepoint list?

The reason why you met that problem is that one variable could only contain one value or one record.

If you select another item, the previous variable value will not be saved.

I suggest you save selected items to a collection, which could contains multiple items value.

Then use this collection to update.

Please set the checkbox's OnCheck:

Collect(selecteditems,ThisItem)

the checkbox's OnUncheck:

Remove(selecteditems,ThisItem)

 patching command:

ForAll(selecteditems,
Patch(
    'Desk Reservations',
    Defaults('Desk Reservations'),
    {
        Title: currentUser.FullName & " " & selecteditems[@Title],
        DeskText: selecteditems[@Title],
        'Check In': startTime,
        'Check Out': endTime,
        'Reserved By': {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & currentUser.Email,
            Department: "",
            DisplayName: currentUser.FullName,
            Email: currentUser.Email,
            JobTitle: "",
            Picture: ""
        }
    }
)
);Navigate(Success)

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @AnthonyRegnier ,

Have you checked my solution?

Have your problem been solved?

If yes, could you mark my answer as solution?
Thanks!

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
SkiDK
Solution Sage
Solution Sage

Hi @AnthonyRegnier 

I would create a collection with an extra column and assign that one to the gallery.

 

ClearCollect(colData, AddColumns(SP_List), "Checked", false))

 

Then assign 'colData' to your gallery as items. Then in the 'Default' option for you checkbox add next:

 

ThisItem.Checked

 

 In OnCheck of the checkbox:

 

Patch(
    colData,
    ThisItem,
    {
        Checked: true
    }
)

 

In OnUncheck of the checkbox:

 

Patch(
    colData,
    ThisItem,
    {
        Checked: false
    }
)

 

So now we will know for each item whether it is checked or not.

To patch the bunch, you can now do next:

 

ForAll(
  Gallery1.AllItems,
  If(
    Checked,
    Patch(
      'Desk Reservations',
      Defaults('Desk Reservations'), //if you want new, if you want update => link to ThisItem
      {
        Title: ...
      }
    )
  )
)

 

Hope this helps!

v-yutliu-msft
Community Support
Community Support

Hi @AnthonyRegnier ,

Do you want to use multiple selected items in a gallery to update a sharepoint list?

The reason why you met that problem is that one variable could only contain one value or one record.

If you select another item, the previous variable value will not be saved.

I suggest you save selected items to a collection, which could contains multiple items value.

Then use this collection to update.

Please set the checkbox's OnCheck:

Collect(selecteditems,ThisItem)

the checkbox's OnUncheck:

Remove(selecteditems,ThisItem)

 patching command:

ForAll(selecteditems,
Patch(
    'Desk Reservations',
    Defaults('Desk Reservations'),
    {
        Title: currentUser.FullName & " " & selecteditems[@Title],
        DeskText: selecteditems[@Title],
        'Check In': startTime,
        'Check Out': endTime,
        'Reserved By': {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & currentUser.Email,
            Department: "",
            DisplayName: currentUser.FullName,
            Email: currentUser.Email,
            JobTitle: "",
            Picture: ""
        }
    }
)
);Navigate(Success)

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

AnthonyRegnier
Helper V
Helper V

Thank you guys for your answers!

I'll check that out today or tomorrow latest and let you know!

Hi @AnthonyRegnier ,

Have you checked my solution?

Have your problem been solved?

If yes, could you mark my answer as solution?
Thanks!

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

AnthonyRegnier
Helper V
Helper V

Yes it worked like a charm, thanks a ton!

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

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (62,007)