Skip to main content

Search

isMemberOfGroup for a specific User and not the current one

Comments

2 comments

  • Christof Nussbaumer

    Hi Joel

    There is no built-in function or hidden functionality to check this so far.

    The technical possibility of this new function was in discussion in our development team and needs some more investigation.
    Since these functionality is all running in client context it's needed to check if these queries would work for all users... and some more research is needed before starting an implementation.

    You can expect further updates about this topic here.

     

    0
  • Matthias Walter

    Hi  Joel Grütter,

    Our investigations have shown that it would be technically possible and that it is possible to read out the group memberships of other users even as a read-only user.
    Currently this can be achieved via the following script.

    //jQuery.Deferred used to wait while it checking
    var deferrer = jQuery.Deferred();
    //Name of Group to check
    var groupName = "Group Name";
     
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    //Use People or Group Field and take ID of user in it
    var user = web.get_siteUsers().getById([[UserFieldSingle.ID]]);
     
    context.load(user);
    var groups = user.get_groups();
    context.load(groups);
    context.executeQueryAsync(
             Function.createDelegate(null, loadUserGroupsSuccess),
             Function.createDelegate(null, loadUserGroupsFail)
    );
    function loadUserGroupsSuccess() {
            var gEnumerator = groups.getEnumerator();                        
            var belongstoSpecifiedgroup = false;
            while (gEnumerator.moveNext()) {
                var currGroup = gEnumerator.get_current();
                if (currGroup.get_title().toLowerCase() == groupName.toLocaleLowerCase()) {
                    belongstoSpecifiedgroup = true;
                    break;
                }
            }
     
    //Resolve deferred with value
    deferrer.resolve(belongstoSpecifiedgroup);
     
    }
     
    function loadUserGroupsFail(sender,args) {
    //reject deferred with error
      deferrer.reject(args.get_message());
    }
     
    return deferrer.promise();

    In order to include it as an easy-to-use function in our expressions, I must ask you, to add this as an idea and give your vote for it.

    https://my.skybow.com/hc/en-us/community/topics/360000696439-Solution-Studio-Online-Ideas

    1

Please sign in to leave a comment.