I have a SharePoint group name "Admin".

Can someone provide me JavaScript code to check if the current logged in user belongs to this group?

I have a query which I want to run based on this condition.

  • Hi Robert, I could not enter long text which include code in comment box, there is limitation to that – Brishal May 19 '15 at 10:13
function CheckMemberInAdminGroup() {    
    var clientContext = new SP.ClientContext.get_current();
    this.currentUser = clientContext.get_web().get_currentUser();

    this.userGroups = this.currentUser.get_groups();
    clientContext.executeQueryAsync(success, failure);

function success() {
         var groupsEnumerator = this.userGroups.getEnumerator();
          while (groupsEnumerator.moveNext()) {
             var group = groupsEnumerator.get_current();               
             if(group.get_title() == "Admin") {
                 // User is member of Admin group, do stuff

function failure() {
          // Something went wrong with the query
| improve this answer | |
  • Thanks, do i need to upload any js file? i yes please provide me the file name also – Brishal May 14 '15 at 14:33
  • What do you mean? You will need to add this JavaScript onto the page, either by pointing to a .js file or adding the JavaScript into a Content Editor Web Part. You don't need any third party libraries, if that's what you're asking. – Submits May 14 '15 at 14:34
  • Just a note, you'll need to use something like ajax createDelegate or jquery $.proxy to pass the "this" object: clientContext.executeQueryAsync($.proxy(this, "success"), $.proxy(this,"failure")); – Anders Aune May 14 '15 at 22:29

Check if user is member of group using JSOM:

function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

        var currentContext = new SP.ClientContext.get_current();
        var currentWeb = currentContext.get_web();

        var currentUser = currentContext.get_web().get_currentUser();

        var allGroups = currentWeb.get_siteGroups();

        var group = allGroups.getByName(groupName);

        var groupUsers = group.get_users();


        function OnSuccess(sender, args) {
            var userInGroup = false;
            var groupUserEnumerator = groupUsers.getEnumerator();
            while (groupUserEnumerator.moveNext()) {
                var groupUser = groupUserEnumerator.get_current();
                if (groupUser.get_id() == currentUser.get_id()) {
                    userInGroup = true;

        function OnFailure(sender, args) {


function IsCurrentUserHasContribPerms() 
  IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
        // The current user is in the [Members] group!

ExecuteOrDelayUntilScriptLoaded(IsCurrentUserHasContribPerms, 'SP.js');
| improve this answer | |

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.