tab control and right

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Malboro
Posts: 28
Joined: Wed Mar 09, 2016

10 Mar 2016

Hi,

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

Thanks

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

11 Mar 2016

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://spform.com/office-365/cond ... ynamically. 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
Posts: 28
Joined: Wed Mar 09, 2016

11 Mar 2016

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

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

11 Mar 2016

Are you using SharePoint online or SharePoint on-premises?

Eax
Posts: 32
Joined: Wed Oct 28, 2015

15 Mar 2016

its SharePoint online

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

15 Mar 2016

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):

Image

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.

Image

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

Code: Select all

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://spform.com/office-365/cond ... ynamically (you can use the code above to determine if the current user is a member of a group or not).

Eax
Posts: 32
Joined: Wed Oct 28, 2015

16 Mar 2016

Thank you so much rostislav

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests