Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to check if the user exists in a particular SharePoint group using ECMAScript
WhatsApp
Vijai Anand Ramalingam
10y
29.5
k
0
0
25
Blog
In this blog you will see how to check if the user exists in a particular SharePoint group using ECMAScript.
<script type=
"text/javascript"
>
ExecuteOrDelayUntilScriptLoaded(IsUserExists,
"sp.js"
);
var
group;
var
users;
var
ctx;
var
groupCollection;
var
user;
var
currentuser;
function
IsUserExists() {
ctx = SP.ClientContext.get_current();
groupCollection = ctx.get_web().get_siteGroups();
currentuser=ctx.get_web().get_currentUser();
group = groupCollection.getById(4103);
ctx.load(group);
ctx.load(currentuser);
ctx.executeQueryAsync(Function.createDelegate(
this
,
this
.OnGetGroupSuccess), Function.createDelegate(
this
, OnFailure));
}
function
OnGetGroupSuccess() {
users=group.get_users();
ctx.load(users);
ctx.executeQueryAsync(Function.createDelegate(
this
,
this
.OnGetuserSuccess), Function.createDelegate(
this
, OnFailure));
}
function
OnGetuserSuccess() {
var
userEnumerator = users.getEnumerator();
while
(userEnumerator.moveNext()) {
var
user = userEnumerator.get_current();
if
(user.get_id() == currentuser.get_id()) {
alert(
"User Exists"
)
break
;
}
else
{
}
}
}
function
OnFailure(sender, args) {
alert(
"Failed to execute IsCurrentUserMemberOfGroup method"
);
}
</script>
How to check if the user exists in a particular SharePoint group using ECMAScript
Up Next
Programmatically Check whether Current Logged in User is a Member of SharePoint User Group or Not
Ebook Download
View all
Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS
Read by 4.9k people
Download Now!
Learn
View all
Membership not found