2

How to get the users of SharePoint security group in JSOM.?

I followed several articles including this one: How to get user security group name through javascript

But none of them were helpful.

1 Answer 1

1

You could probably use Microsoft Graph and the List members with adaljs.

Should be possible to delegate the permissions needed:

Delegated (work or school account)
Directory.Read.All, Directory.AccessAsUser.All, User.ReadBasic.All, User.Read.All

Edit:

I did a quick test, and its working okey:

$.ajax({
    url: "https://graph.microsoft.com/beta/groups?$filter=displayName eq 'EN-ANSATTE'&$select=id", 
    method: "GET", 
    headers: {
        'Authorization': 'Bearer ' + token,
        'Accept' : 'application/json; odata.metadata=none',
    },
    success: function(data) {                

        if(data.value.length) {

            $.ajax({
                url: "https://graph.microsoft.com/beta/groups/"+ data.value[0].id +"/members", 
                method: "GET", 
                headers: {
                    'Authorization': 'Bearer ' + token,
                    'Accept' : 'application/json; odata.metadata=none',
                },
                success: function(dataMembers) {                

                    dataMembers.value.forEach((ele) => {
                        if(ele.percentComplete != 100) {
                            console.log( ele.userPrincipalName )
                        }
                    })

                }, 
                error: function(err) {
                    console.log(err)
                }
            })
        }      
    }, 
    error: function(err) {
        console.log(err)
    }
})

You'll have add an app with permissions etc to azure ad and get the token with adaljs. Lots of blogs how that's done on google

2
  • And h0ow to get the token value.? Not getting any article, clearly. Commented Sep 1, 2017 at 8:43
  • @DilipKumarYadav you can check this blogpost out: julieturner.net/series/… , should cover most iguess Commented Sep 1, 2017 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.