I have setup a metadata navigation. But now i only want sites to be visible for users that are members on this sites. Security triming does not works with metadata navigation, i was thinking some solution with jsom?


Yes, you can use a script to determine the presence of a user in the group:

function isCurrentUserInGroup(groupName, functionUserInGroup, functionUserNotInGroup, functionGroupNotFound, functionOnError) { 
    var ctx = new SP.ClientContext.get_current(); 
    //Get info of current user 
    var currentUser = ctx.get_web().get_currentUser(); 
    ctx.load(currentUser, 'Id', 'LoginName'); 
    //Retrieve all site groups 
    var groups = ctx.get_web().get_siteGroups(); 

    ctx.executeQueryAsync(function (sender, args) { 
        //See whether the group exists 
        var groupFound = false; 
        var groupEnumerator = groups.getEnumerator(); 
        while (groupEnumerator.moveNext() && !groupFound) { 
            var group = groupEnumerator.get_current(); 
            if (group.get_title() == groupName) { 
                //Found the group, now try to load users of this group 
                groupFound = true; 
                var users = group.get_users(); 
                ctx.executeQueryAsync(function (sender, args) { 
                    //See whether the user exists 
                    var userFound = false; 
                    var userEnumerator = users.getEnumerator(); 
                    while (userEnumerator.moveNext() && !userFound) { 
                        var user = userEnumerator.get_current(); 
                        if (user.get_id() == currentUser.get_id()) { 
                            //User exists in the group 
                            userFound = true; 

                            if (functionUserInGroup != null) 

                    //User doesn't exist in the group 
                    if (!userFound && (functionUserNotInGroup != null)) 

                }, function (sender, args) { 
                    if (functionOnError != null) 
                        functionOnError(sender, args); 


        //Group doesn't exist 
        if (!groupFound && (functionGroupNotFound != null)) 

    }, function (sender, args) { 
        if (functionOnError != null) 
            functionOnError(sender, args); 



Example of using:

ExecuteOrDelayUntilScriptLoaded(function () { 
        function () { 
            alert('User is in the group.'); 
            var field = new Igotta.StandartListFormsUtility.SPFieldText('Title');
        function () { 

        function () { 
            alert('Group does NOT exist.'); 
        function (sender, args) { 
            alert('Request failed.' + args.get_message() + '\n' + args.get_stackTrace()); 
    }, "sp.js"); 

Now you have information about user group. Now add the logic to hide menu items

  • 1
    Thank you so much, i will try it with modifying my changes – Anders Apr 2 '14 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.