cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Wave
Advocate I
Advocate I

Patch or Collect entire Collection to Sharepoint with People column

Gallery has a list of people and their info from a filtered sharepoint list collection where they all have the same 'SID'. This filtered collection is not and will never be a very large list, say max 50. People are added and removed from the gallery and the collection is updated with no problems. There is a save button so when user is done editing the gallery the sharepoint list is updated. The way it works is first all the items in list with that same SID (the items initially used to create the gallery collection) are deleted. After that the entire collection should be added to the list. Maybe deleting all rows by SID isnt the best way to get this done, but I'm having trouble just adding as new items, so going through and updating any changes, deleting removed and adding new...

I have never updated to sharepoint lists before and just 😕

I have tried Patch with and without ForAll but it only adds one item, and with forall adds same more than once.

Patch(SPList,
Defaults(SPList),
{ Title:GalLabTitle_1.Text,
'SID':Combobox_1.Selected.SID,
.
.
.
'Name': {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:"i:0#.f|membership|"& GalLabEmail_1.Text,
Department:GalLabDept_1.Text,
DisplayName:GalLabName_1.Text,
Email:GalLabEmail_1.Text,
'Phone Number': GalLabTelephone_1.Text,
JobTitle:"",
Picture:""
}})

I have tried collect and it adds all of them but the person column is blank.

Collect(SPList,ShowColumns(Filter(collectSPList, SID = Combobox_1.Selected.SID),"Title","Name"....)))

____________________________________________________________


Edit: Initial Collection1 is created from existing Sharepoint list. Name, SID, SortOrder are the 3 main columns. The collection is used in several places on in the app.
Collection2 is created from Collection1 by a filter, all items with SID = Dropdown_SIDList,

ClearCollect(  Collection2 , Filter(Collection1 , SID = Dropdown_SIDLis))

Collection2 are the items in the Gallery, they have a SortOrderID column than can be edited. Items in the Gallery can be deleted, added and/or SortOderID changed. Save Button ideally would do two things 1- delete all items in sharepoint list with SID = Dropdown_SIDList and 2- add the entire Collection2 as new data including the person Name.Displayname.

RemoveIf(SPList, SID = Dropdown_SIDList.selected.Value);
Collect(SPList,Collection2)


Help please

3 REPLIES 3
FabianAckeret
Super User
Super User

Hi @Wave 

 

You could use ForAll to patch an entire collection to SharePoint, like so:

ForAll(
    <your collection including all people>,
    Patch(
        SPList,
        Defaults(SPList),
        {
            'First Name': 
                {
                    Claims: "i:0#.f|membership|" & ThisRecord.<your field>.Email,
                    Department: ThisRecord.<your field>.Department,
                    DisplayName: ThisRecord.<your field>.DisplayName,
                    Email: ThisRecord.<your field>.Email,
                    JobTitle: ThisRecord.<your field>.JobTitle,
                    Picture: ""
                }
        }
    )
)

 

I hope this helps.


Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.

 

Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.

Thanks for replying @FabianAckeret 

I was sure it would work I put it in just like you wrote but unfortunately it only adds the new people. Even though I have it set to delete all rows with certain SID somehow it does not insert all rows only the new ones. even the ones that already existed in list that I changed are not added back after deleted.I tried it with and without Default(SPlist)

I have updated my question to explain the list collection relationship

Wave
Advocate I
Advocate I

I was under the assumption that Patch would, well patch. That is if it changed fix it, if it was deleted delete if it's new add it. Apparently not.
I had to split what I needed done into three parts. All columns in SPList and Collection are the same except ID/cID and SortOrder/cSortOrder. sortorder is the only thing user allowed to edit in list
Step 1

ForAll cID If SPList ID Not in Collection cID create collection of IDs. then loop through it and Delete them from SPList
Step 2
ForAll If SPList ID is in Collection cID then update in SPList the SortOrder = cSortOrder 
Step 3
ForAll  cID = 0, Patch them in SPList with Default to create new entries.

 

Not the ideal solution and definitely not the pretties, but it works.

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

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

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

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (70,853)