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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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