AnsweredAssumed Answered

Determining Group Membership with CSOM

Question asked by johncoltrane on Feb 1, 2016
Latest reply on Mar 24, 2017 by fhunth

I'm attempting to adapt this post: Hide Edit Item button if user is not allowed to edit using to determine if the current user is a member of a SharePoint group. Here's my code:

 

var pollSP;

var groupName = "SP GroupName";

NWF.FormFiller.Events.RegisterAfterReady(function () {

    pollSP = setInterval(checkSPLoad, 500);

});

function checkSPLoad() {

    if (clientContext) {

        window.clearInterval(pollSP);

        onSPLoad();

    }

}

function onSPLoad(groupName) {

     //Our code must come here

alert("starting");

var context = new SP.ClientContext.get_current();

var currentWeb = context.get_web();

var currentUser = context.get_web().get_currentUser();

 

context.load(currentUser);

 

var allGroups = currentWeb.get_siteGroups();

context.load(allGroups);

 

var group = allGroups.getByName(groupName);

context.load(group);

       

var groupUsers = group.get_users();

context.load(groupUsers);

  

context.executeQueryAsync(

                function(sender, args) {

                   var userInGroup = IsUserInGroup(currentUser,group);        

                   alert(userInGroup);

                },

                function OnFailure(sender, args) {

                    alert(args.get_message());

                }

        );

}

function IsUserInGroup(user,group)

        {

            var groupUsers = group.get_users();

            var userInGroup = false;

            var groupUserEnumerator = groupUsers.getEnumerator();

            while (groupUserEnumerator.moveNext()) {

                var groupUser = groupUserEnumerator.get_current();

                if (groupUser.get_id() == user.get_id()) {

                    userInGroup = true;

                    break;

                }

            }

            return userInGroup;

        }

 

When I run it I receive this error:

https://formso365.nintex.com/Pages/Formspart/_api/contextinfo 404 (not found)

 

How can I get the context in Office 365 Nintex?

 

Thanks in advance.

Outcomes