cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GavSirisena
Frequent Visitor

Patching updates to multiple person field in SharePoint without over-writing

Hi community!

I haven't been able to find an answer to this and I have looked, apologies if it is out there.

 

We have a sharepoint list that is being used for an events booking app with a person field for 'Attendees'.

Desired functionality: When Users click a button, it adds their name to the Attendees field, in addition to any names that are already there.

What is happening when using this Patch code below is that it is over-writing what is there, I need it to append...any ideas?

Patch(Training, Gallery1.Selected, {Attendees:
Table({
'@odata.type': "#Microsoft​.Azure.Connectors.SharePoint.SPListExpandedUser",
Department: "",
Claims: "i:0#.f|membership|" & User().Email,
DisplayName: User().FullName,
Email: User().Email,
JobTitle: "",
Picture: ""
})
}
);


2 ACCEPTED SOLUTIONS

Accepted Solutions
RusselThomas
Microsoft
Microsoft

Hi @GavSirisena ,

You're overwriting a table of possibly multiple people with a table of one person.

The idea would be to get the table of existing people, add your person to it, then write the table back.

Try this;

ClearCollect(collectMultiPersons, Gallery1.Selected.Attendees); //collect current attendees
Collect(collectMultiPersons, //add this attendee to the collection
{
'@odata.type': "#Microsoft​.Azure.Connectors.SharePoint.SPListExpandedUser",
Department: "",
Claims: "i:0#.f|membership|" & User().Email,
DisplayName: User().FullName,
Email: User().Email,
JobTitle: "",
Picture: ""
});

Patch(Training, Gallery1.Selected, {Attendees: collectMultiPersons})  //overwrite the existing table with your collection 

I'm not sure if there's a more efficient way of adding a single person to an existing list of people, but as the underlying data type is complex, it may in turn be quite complicated.

Hope this helps,

RT

View solution in original post

RandyHayes
Super User
Super User

@GavSirisena 

Please consider changing your Formula to the following:

With({_itm: Gallery1.Selected, _usr: User()},

   UpdateIf(Training, ID=_itm.ID, 
       {Attendees:
           Ungroup(
               Table(
                   {Item: 
                     Table({Department: "",
                            Claims: "i:0#.f|membership|" & Lower(_usr.Email),
                            DisplayName: _usr.FullName,
                            Email: _usr.Email,
                            JobTitle: "",
                            Picture: ""
                           }
                      )
                   },
                   {Item: _itm.Attendees}
               ),
               "Item"
           )
       }
   )
);

This will include the current user in the Attendees Person column while maintaining the existing users that are already there.

The collection method can be used, but if you're trying to avoid clutter in your app, the above will work without the heavyweight collection as well.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RusselThomas
Microsoft
Microsoft

Hi @GavSirisena ,

You're overwriting a table of possibly multiple people with a table of one person.

The idea would be to get the table of existing people, add your person to it, then write the table back.

Try this;

ClearCollect(collectMultiPersons, Gallery1.Selected.Attendees); //collect current attendees
Collect(collectMultiPersons, //add this attendee to the collection
{
'@odata.type': "#Microsoft​.Azure.Connectors.SharePoint.SPListExpandedUser",
Department: "",
Claims: "i:0#.f|membership|" & User().Email,
DisplayName: User().FullName,
Email: User().Email,
JobTitle: "",
Picture: ""
});

Patch(Training, Gallery1.Selected, {Attendees: collectMultiPersons})  //overwrite the existing table with your collection 

I'm not sure if there's a more efficient way of adding a single person to an existing list of people, but as the underlying data type is complex, it may in turn be quite complicated.

Hope this helps,

RT

RandyHayes
Super User
Super User

@GavSirisena 

Please consider changing your Formula to the following:

With({_itm: Gallery1.Selected, _usr: User()},

   UpdateIf(Training, ID=_itm.ID, 
       {Attendees:
           Ungroup(
               Table(
                   {Item: 
                     Table({Department: "",
                            Claims: "i:0#.f|membership|" & Lower(_usr.Email),
                            DisplayName: _usr.FullName,
                            Email: _usr.Email,
                            JobTitle: "",
                            Picture: ""
                           }
                      )
                   },
                   {Item: _itm.Attendees}
               ),
               "Item"
           )
       }
   )
);

This will include the current user in the Attendees Person column while maintaining the existing users that are already there.

The collection method can be used, but if you're trying to avoid clutter in your app, the above will work without the heavyweight collection as well.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
GavSirisena
Frequent Visitor

You're a genius Russel! Thank you very much for this solution, it worked exactly as I needed it to.

Hi Randy, this also worked really well and was probably a bit faster so thanks a lot!

Hi @RandyHayes 

 

this also works fine for me. However i have another question.

 

I want to Patch all the previous selected users of my Combobox and the newly selected ones to my person column.(Multi selection enabled).

 

My Combobox Properties: 

Filter(Office365Users.SearchUser({searchTerm:ExtendedProjectTeam_input.SearchText}),AccountEnabled=true,Not(IsBlank(Mail)),Not(IsBlank(Department)),Not(IsBlank(JobTitle)))

Default and default selected items are

LookUp(Request,ID = RequestID).ExtendedProjectTeam

 

 

With({_itm: varItem , _usr: User()},
    UpdateIf(Request,ID = _itm.ID,
        {memberstest:
            Ungroup(Table(
                {Item:
                    Table({ Department: "",
                            Claims: "i:0#.f|membership|" & Lower(_usr.Email),
                            DisplayName: _usr.FullName,
                            Email: _usr.Email,
                            JobTitle: "",
                            Picture: ""
                           })
                },
                   {Item: _itm.memberstest}
               ),
               "Item"
           )
       }
   )
);

 i want to patch these users into a separate column of persons in order to later add them to a team in teams

 

BR Niklas

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 (5,455)