Wednesday, April 27, 2016

Providing different forms for different users in SharePoint Online

If you want to create different forms to different types of users in Forms Designer for SharePoint Online, you have two options: use permission settings or use SharePoint groups. We’ll look at both options in this article.

Suppose we have two types of users on our SharePoint website: managers and regular users. Managers have elevated privileges and we want to give them a particular set of functionality in a form. And regular users should receive a smaller or a different set of functionality and we want to give them a default form.

What we will do first is create an additional form set for managers using the plus button in the top right corner of Forms Designer.

Adding multiple form sets for a SharePoint list

Using permission settings

SharePoint has inbuilt permissions that we will utilize to distinguish managers from non-managers. Please check this list to see the available permissions:
https://msdn.microsoft.com/EN-US/library/ms412690.

We will pick CreateGroups to differentiate managers from non-managers, as only managers are allowed to create groups on our website.

We then will add an html control onto the default form in Forms Designer and paste the following html code inside it:

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="CreateGroups" EmitDiv="true">
<script type="text/javascript">
    fd.openForm('fd_Item_52b1ac46-b55e-4d3c-9807-dec2a57b2e9f_EditForm.aspx');
</script>
</Sharepoint:SPSecurityTrimmedControl>
Using SPSecurityTrimmedControl in a SharePoint form

We have used CreateGroups permission string and the name of the form where we want our managers to be redirected to. The name of the form can be seen if you go to the appropriate form set in Forms Designer (in our case it’s Manager) and pick the appropriate form (in our case it’s Edit Form). That is the form that managers will be redirected onto:

SharePoint form filename

Now whenever a manager opens the default edit form he or she will be redirected to his manager-only form, while a non-manager will stay on the default form.

Using SharePoint groups

Another choice we have to set up user group specific forms is by utilizing SharePoint groups.

For this we’ll need to add a JavaScript script to document library. Create a file named redirect.htm and add the following code to it:

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(function () {
 fd.openForm('fd_Item_ee433778-833d-4154-a72f-f68dc876fdc5_EditForm.aspx');
}, 'plumsail.fd.core.js');
</script>

Again, you’ll need to replace the filename as before.

Upload redirect.htm to a document library on your website. Take note of its URL.

Now to go the list with your form sets. Click to edit one of the three forms, we’ll be editing the Edit Form.

Editing SharePoint form page

You’ll be redirected to the default edit form in edit mode, click “Add a Web Part” and add a Content Editor webpart:

Adding Content Editor Web Part to a SharePoint form

Click the Content Editor Webpart’s little arrow button and click Edit.

Enter the URL of redirect.htm into the box:

Setting Content Link property of the Content Editor Web Part

Expand Advanced and enter the SharePoint group members of which you want to be redirected to the additional edit form, in our case it’d be the site collection owners that will be redirected to the Manager edit form:

Settings Target Audiences property of the Content Editor Web Part

Click OK.

Now all members of the group will be redirected to the Manager edit form, while non-members will stay on the default form.

8 comments:

  1. Dmitry

    I am trying to display different edit forms to different groups as per your instructions “Using SharePoint groups”. I need 3 different versions of the form: - managers, secretaries and surveyors (default). I set up a version for managers. That works fine. Surveyors are taken care of by the default edit form, so that’s fine too. I have tried to set up a third version for secretaries, but it just won’t work – they see the default version.

    Is there a limit to the number of form versions that can be displayed using this method? Or what am I doing wrong?

    Regards
    Rom

    ReplyDelete
    Replies
    1. Hi Rom,
      There are no limits on the number of forms. You just need to place the appropriate number of Content Editor web parts onto your default form (one per group) and set the corresponding values in Content Link and Target Audiences properties.

      Delete
    2. Hi Dmitry
      That’s what I have been doing, but it’s still not working. Once I have created the Content Editor web part on the default edit form, I can’t access it again once I have clicked OK. At least it does display the correct form for the chosen group. I then add the second Content Editor web part form, and once again, I can’t access to edit it once I have clicked OK. This one doesn’t work. What am I doing wrong?

      Delete
    3. Hi Rom,
      Create empty files redirect1.html, redirect2.html. Then configure the web parts. And finally, set up the redirections in the redirect1.html and redirect2.html.

      Delete
  2. Hi Dmitry,
    I configured the above using Sharepoint Groups on my Display form and it works great. Now, I want to delete this feature since I no longer need to have multiple Display forms.

    When I attempt to Edit the Display Form (as I did when setting this up), I am unable to see any content editor web part on the page. Since I can't view the web part, I obviously can't edit it.

    Any ideas on where it may have went? The multiple Display forms are obviously still working, so the web part has to be there somewhere.

    Thanks in advance

    ReplyDelete
    Replies
    1. I have gathered more information which I hope can help in figuring this out.

      Although I cannot see the CEWP on the page, I viewed the existing web parts on the page by adding &contents=1 at the end of my URL, and sure enough I can see the CEWP there. I deleted the CEWP, thinking that once deleted it would not be able to fire the redirect.html, to no avail. I modified the redirect.html file to a random string to confirm it was still being fired, and it did redirect me to the new string I entered, This tells me that something is still firing the redirect, I just can't find it to modify it!

      Any help you can provide is appreciated.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Using the second method, the page redirects successfully to the managers edit page. However, it keeps the &source= with the link of the basic users edit page. So what happens when I click save is it goes to the basic edit page, sees that the user is a manager and loads the managers page. how can I remove the &source= object from the redirection?

    ReplyDelete

Note: Only a member of this blog may post a comment.