REST API to check login user groups
/* Check Current user Permission Level or User Group */
function getCurrentUserReviewerAndApprover() {
var currentUserRole = "";
jQuery.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + _spPageContextInfo.userId + ")/Groups",
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var results = data.d.results;
var isVisitor = false;
var isMember= false;
var isOwener= false;
//var groupInfo = jQuery.grep(results, function (group) {
jQuery.grep(results, function (group) {
if (group.Title === "Visitor") {
isVisitor = true;
}
if (group.Title === "Member")
{
isMember= true;
}
if (group.Title === "Owners")
{
isOwener= true;
}
var groupTitleReviewers = group.Title;
if (groupTitleReviewers.indexOf("Reviewers") > -1) {
isReviewer = true;
}
});
if (isVisitor ) {
currentUserRole = "Visitor";
}
if (isMember) {
currentUserRole = "Member";
}
if (isOwener {
currentUserRole = "Owener";
}
},
error: function (error) {
alert(error);
}
});
return currentUserRole;
}
Happy Coding....Sharing is caring .... Keep Smiling...
function getCurrentUserReviewerAndApprover() {
var currentUserRole = "";
jQuery.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + _spPageContextInfo.userId + ")/Groups",
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var results = data.d.results;
var isVisitor = false;
var isMember= false;
var isOwener= false;
//var groupInfo = jQuery.grep(results, function (group) {
jQuery.grep(results, function (group) {
if (group.Title === "Visitor") {
isVisitor = true;
}
if (group.Title === "Member")
{
isMember= true;
}
if (group.Title === "Owners")
{
isOwener= true;
}
var groupTitleReviewers = group.Title;
if (groupTitleReviewers.indexOf("Reviewers") > -1) {
isReviewer = true;
}
});
if (isVisitor ) {
currentUserRole = "Visitor";
}
if (isMember) {
currentUserRole = "Member";
}
if (isOwener {
currentUserRole = "Owener";
}
},
error: function (error) {
alert(error);
}
});
return currentUserRole;
}
Happy Coding....Sharing is caring .... Keep Smiling...
Comments
Post a Comment