Adding group to the particular list or library in sharepoint

%3CLINGO-SUB%20id%3D%22lingo-sub-774643%22%20slang%3D%22en-US%22%3EAdding%20group%20to%20the%20particular%20list%20or%20library%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-774643%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20want%20to%20add%20group%20to%20the%20particular%20library%20or%20list%20in%20share%20point%202013%2C%20am%20using%20spfx%20i%20need%20any%20api%20or%20solution%20for%20the%20above%20question%2C%20please%20kindly%20help%20me%20to%20fix%20the%20issue%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-775484%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20group%20to%20the%20particular%20list%20or%20library%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-775484%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F382537%22%20target%3D%22_blank%22%3E%40Madhusudana_Yadav_N%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20mean%20you%20have%20a%20a%20list%2Flibrary%20with%20a%20fied%20of%20type%20%22User%2F%20Group%22%20and%20you%20want%20to%20set%20this%20value%20from%20your%20SPFX%20solution%3F%3C%2FP%3E%3CP%3EIf%20yes%2C%20then%20you%20can%20use%20the%20PnPJS%20library%20to%20update%20it.%20Considering%20you%20have%20a%20field%20%22Owner%22%20of%20type%20User%2F%20Group%20and%20a%20%22Members%22%20field%20that%20supports%20multiple%20Users%2F%20Groups%2C%20you%20can%20update%20it%20using%3A%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22nx%22%3Esp%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eweb%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Elists%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3EgetByTitle%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E(%3CLISTTITLE%3E%3C%2FLISTTITLE%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E).%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eitems.getById(%3CITEMID%3E).update(%7B%3CBR%20%2F%3E%20%20%20%20%20OwnerId%3A%20%3CUSERID%3E%2C%3CBR%20%2F%3E%20%20%20%20%20MembersId%3A%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20results%3A%20%5B%3CUSER1ID%3E%2C%20%3CGROUP1ID%3E%5D%3CBR%20%2F%3E%20%20%20%20%20%7D%3CBR%20%2F%3E%7D)%3C%2FGROUP1ID%3E%3C%2FUSER1ID%3E%3C%2FUSERID%3E%3C%2FITEMID%3E%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BSo%20basically%2C%20you%20need%20to%20append%20%22Id%22%20to%20the%20end%20of%20the%20field%20name%20and%20set%20it%20to%20ID%20of%20the%20User%2F%20Group%20you%20want.%20If%20it%20is%20a%20multiple%20people%20field%2C%20then%20you%20have%20to%20set%20it%20to%20an%20object%20containing%20a%20%22results%22%20array%2C%20in%20which%20each%20value%20is%20an%20user%2F%20group%20ID.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20it%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-787646%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20group%20to%20the%20particular%20list%20or%20library%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-787646%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F365643%22%20target%3D%22_blank%22%3E%40Carlos_Marins%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%20thanks%20for%20ur%20kind%20reply.%3C%2FP%3E%3CP%3EActually%20i%20have%20list%2C%20i%20want%20to%20add%20new%20groups%20to%20the%20existing%20library%2C%20and%20the%20group%20which%20we%20created%20should%20be%20added%20to%20the%20particular%20list%20we%20specified.%3C%2FP%3E%3CP%3EPlease%20kindly%20give%20solution%20or%20code%20snippet%20for%20the%20above%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3EMadhusudana%20Yadav%20N%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi,

I want to add group to the particular library or list in share point 2013, am using spfx i need any api or solution for the above question, please kindly help me to fix the issue

2 Replies
Highlighted

Hey @Madhusudana_Yadav_N ,

 

You mean you have a a list/library with a fied of type "User/ Group" and you want to set this value from your SPFX solution?

If yes, then you can use the PnPJS library to update it. Considering you have a field "Owner" of type User/ Group and a "Members" field that supports multiple Users/ Groups, you can update it using:

sp.web.lists.getByTitle(<ListTitle>).items.getById(<ItemID>).update({
OwnerId: <UserId>,
MembersId: {
results: [<User1ID>, <Group1Id>]
}
})

 So basically, you need to append "Id" to the end of the field name and set it to ID of the User/ Group you want. If it is a multiple people field, then you have to set it to an object containing a "results" array, in which each value is an user/ group ID.

 

Hope it helps.

Highlighted

@Carlos_Marins 

Hi, thanks for ur kind reply.

Actually i have list, i want to add new groups to the existing library, and the group which we created should be added to the particular list we specified.

Please kindly give solution or code snippet for the above problem.

 

Thanks,

Madhusudana Yadav N