title: How can I get a bool value, after I check if current user in sharepoint group in javascript?
body: <ul>
  <li><strong>JS Function</strong></li>
  </ul>
  
  <p>I write a function to check if user in sharepoint group in javascript</p>
  
  <blockquote>
  <pre><code>function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
  var currentContext = new SP.ClientContext.get_current();
  var currentWeb = currentContext.get_web();
  var currentUser = currentContext.get_web().get_currentUser();
  currentContext.load(currentUser);
  var allGroups = currentWeb.get_siteGroups();
  currentContext.load(allGroups);
  currentContext.load(allGroups, 'Include(Users)');
  currentContext.executeQueryAsync(OnSuccess, OnFailure);
  
  function OnSuccess(sender, args) {
      var userInGroup = false;
      var groupEnumerator = allGroups.getEnumerator();
      while (groupEnumerator.moveNext()) {
          var oGroup = groupEnumerator.get_current();
          if (groupName == oGroup.get_title()) {
              var allUsers = oGroup.get_users();
              var userEnumerator = allUsers.getEnumerator();
              while (userEnumerator.moveNext()) {
                  var oUser = userEnumerator.get_current();
                  if (oUser.get_id() == currentUser.get_id()) {
                      userInGroup = true;
                      break;
                  }
              }
          }
  
      }
      OnComplete(userInGroup);
  }
  
  function OnFailure(sender, args) {
      OnComplete(false);
  }   }
  </code></pre>
  </blockquote>
  
  <ul>
  <li><strong>Usage</strong></li>
  </ul>
  
  <p>I use it in another function, wish to get the bool value of <strong>OnComplete</strong> and return it.</p>
  
  <blockquote>
  <pre><code>function SetButtonPermission() {
  var isInGroup;
  IsCurrentUserMemberOfGroup("Global", function(isCurrentUserInGroup) {
      isInGroup = isCurrentUserInGroup;
  });
  return isInGroup; }
  </code></pre>
  </blockquote>
  
  <ul>
  <li><strong>Question</strong></li>
  </ul>
  
  <p>It seems like I cannot get the bool <strong>isCurrentUserInGroup</strong> because it alert "isInGroup is undetified".
  <strong>So How Can I Get The bool value ?</strong> </p>