Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

How to check whether user is in group or not using javascript/rest api.

$
0
0

Hi,

I am trying to get whether user is in sharepoint group or not. If user is not in group then i need to hide some fields in the page but somehow I am getting undefined value. Please help me to achieve this.Any help would be greatly appreciated.

Here is my script.

<script>

var isAdmin = false; 

$(document).ready(function(){

isAdminGroupMember(isuser);

window.alert("login User is admin:::"+isuser+"");  /// here i am getting undefined result.

if (isuser == true) 

 isAdmin =  true; /// then this value I am going to use in another function to hide fields on page,

}

});

function isAdminGroupMember(isuser) {
  
  var isuser = false;
  
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('Site Admins')/Users?$filter=Id eq " + _spPageContextInfo.userId,
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function(data) {
            if (data.d.results.length == 0) {
            //do nothing
                                        
            } else {
                          isuser = true;   
                
               // window.alert("is user Site Admin: "+isuser+""); 
                             
         
            }
           
        },
        error: function(err) {
            console.log("Error while checking user in Owner's group");            
        }
        
      
    });
    
    
   
    return isuser;
}

</script>


OK29


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>