tab control and right

rss

Posted by Malboro - Mar 10 ’16 at 10:46

Hi,

I want to give right (Group) on my tab control to hide this  for users who don't have right.

Thanks

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 5 days
    #1 by rostislav Mar 11 ’16 at 07:28

    Hi,

    Sorry, don't quite understand you requirements. If you want to present different users (users belonging to different SharePoint groups) different functionality, you can:

    1. Use the Groups functionality if you're using SharePoint on-premises: http://spform.com/documentation/groups together with one of the available functions, for example IsCurrentUserMemberOfGroup. For more information check http://spform.com/documentation/groups/functions. This choice is good if you want to create completely separate forms for different user types.

    2. If you're using SharePoint online you can simulate functionality described in [#1] with Form Sets and JavaScript. Let us know if you need more information on that.

    3. Otherwise, if you only want to hide/show part of the form you can do that with JS also, see http://formsdesigner.blogspot.com/2014/07/how-to-conditionally-hide-disable-make.html. You'll have to use JSOM to determine if the user is in the group or not. Let us know if you need more info on how to do this.

     

  • Malboro
    Member
    Member for: 3 years 9 months 1 day
    #2 by Malboro Mar 11 ’16 at 09:54

  • Malboro
    Member
    Member for: 3 years 9 months 1 day
    #3 by Malboro Mar 11 ’16 at 10:06

    Admins Group can see this tab control but another user can't

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 5 days
    #4 by rostislav Mar 11 ’16 at 11:45

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 5 days
    #5 by rostislav Mar 11 ’16 at 11:48

    [#3]: Are you using SharePoint online or SharePoint on-premises?

  • Eax
    Member
    Member for: 4 years 1 month 12 days
    #6 by Eax Mar 15 ’16 at 10:53

    its SharePoint online

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 5 days
    #7 by rostislav Mar 15 ’16 at 01:26

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 5 days
    #8 by rostislav Mar 15 ’16 at 01:31

    [#7]:

    Basically, you can do one of two things: have separate form sets for different groups of users or simply hide/show parts of the web page based on the current user’s group. If the difference between the two user-specific views is minor you can go for the latter choice, which is probably your case, so you can skip to step 3 below. You won’t need fd.openForm in that case, you’ll need to read the blogpost at the bottom to see how to show and hide different UI elements.

    Otherwise if you want to implement completely different forms for different users, start from step 1.

    1. Create an additional form set in Forms Designer by clicking the plus sign (this form set will be used as a redirect destination for a SharePoint group):

     

    We'll implement this functionality for the edit form. Implementing it for Display and New forms would be exactly the same (although filenames of forms would be different).

    2. Take a note of the filename at the bottom left corner. You will be redirecting your group members to it.

    3. Insert the following code into the JavaScript editor of the form:

    fd.showLoading();
    ExecuteOrDelayUntilScriptLoaded(IsCurrentUserWithContributePerms, 'SP.js');
    
    //function that implements the redirect logic 
    function IsCurrentUserWithContributePerms() 
    {
      //specify the name of the group here instead of “Members”
      IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
        //if the user is definitely in the group
        if(isCurrentUserInGroup){
            // then redirect the user somewhere. Replace this filename with the filename of your form to which a member is to be redirected (see the screenshot above)
            fd.openForm('fd_Item_767bfb1a-7093-46f0-be37-1cf85c917a63_EditForm.aspx');
        }
        //here you will have as many if statements as you have user roles
        else {
            //here is the default choice for users that don’t belong to any groups: 
            //maybe redirect him/her someplace else - use fd.openForm(..) like above
            //or remain on the current page (and show it):
            fd.hideLoading();
        }
      });
    
    }
    
    //function to check if a user belongs to a group  (no need to worry about this)
    function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
    
            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);         
                       OnComplete(userInGroup);
                    },
                    function OnFailure(sender, args) {
                       OnComplete(false);
                    }
            );
            
            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;
            }
    }
    
    

    4. Take a look at the code comments. You will want to specify the name of your group (instead of "Members"), the filename of the form (where it says fd.openForm(...)), implement additional logic for other user roles and possibly implement some default redirect logic  or just show the current default form, which is what happens at the moment.

    5. Repeat the steps 1-4 for Display and New forms.

    If you simply want to hide/show a couple of fields, please read this article http://formsdesigner.blogspot.com/2014/07/how-to-conditionally-hide-disable-make.html (you can use the code above to determine if the current user is a member of a group or not).

     

  • Eax
    Member
    Member for: 4 years 1 month 12 days
    #9 by Eax Mar 16 ’16 at 04:02

    Thank you so much rostislav smile

Displaying 1 to 9 of 9 messages