0

I am trying to get current user group name when the member is added via Active Directory in SharePoint 2013 using Rest/jQuery. Any help is appreciated.

2 Answers 2

0

first you have to use "currentUser" api to get current user id,then try use "GetUserById" function to list all groups.

function getCurrentUser()   
{  
getUserWebPermissionREST();  
$.ajax({  
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/CurrentUser",  
method: "GET",  
headers: { "Accept": "application/json; odata=verbose" },  
success: function (data)  
{  
getCurrentUserGroupColl(data.d.Id);  
},  
error: function (data)   
{  
failure(data);  
}  
});  
}  
function getCurrentUserGroupColl(UserID)   
{  
$.ajax  
({  
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + UserID + ")/Groups",  
method: "GET",  
headers: { "Accept": "application/json; odata=verbose" },  
success: function (data) {  
/* get all group's title of current user. */  
var results = data.d.results; var InnrHtmlgrp = "  
    <ul>";  
for (var i = 0; i < results.length; i++)   
{  
InnrHtmlgrp += "  
        <li>" + results[i].Title + "</li>";  
}  
$("#Group").append(InnrHtmlgrp + "  
    </ul>");  
}  
});  
}  

https://social.technet.microsoft.com/wiki/contents/articles/36658.using-sharepoint-2013-get-current-user-group-collection-through-rest-api.aspx

0
var grp = new SPAPI_UserGroup("https://Site Url"); // pass site url

sLoginUserName1 = "[email protected]";   // email id of the user which is rendering in site

var ug = grp.getGroupCollectionFromUser(sLoginUserName1);

var rows = ug.responseXML.getElementsByTagName('Group');

for (var i=0; i< rows.length; i++){

alert(rows[i].getAttribute('Name'));

}

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.