List Form Fields–Show/Hide For Certain People: Part 2

In this second post of the three part blog series, I will show how you can show or hide fields according to whether or not the currently logged in person is part of a certain SharePoint group.

This is a three part blog:

In this example, I have a task list, and there are only certain people who should be able to edit the task’s due date.  Others should be able to see it but not edit it. This concept is very similar to the concept in the previous blog post, there are just a few things different in the steps.

This solution in part 2 can be done with any enterprise version of SharePoint: MOSS, SharePoint 2010, even SharePoint Online with Office 365 (enterprise plans).

  1. Create a custom list on your site, just to keep a single item in, with a very simple purpose that will be apparent as we go.  I’ll call it “Single Item”.  Add one item to the list, just type anything in the Title field.
  2. Open SharePoint Designer.  In Lists and Libraries, open your task list.  In the Forms section on the right, click the New button.
  3. Call your new file EditCustom, pick Edit item form, and check the box to set as default.  Click OK.
  4. Click the name of your new EditCustom.aspx form to open it.
  5. Click your cursor inside the form on the screen somewhere, so that the contextual ribbon will show the appropriate options.  Click the Parameters button on the Options tab.
  6. Click the New Parameter button.  Call it the FilterParam, select Query String, and type Filter as the query string variable.  Click OK.  (side note: all those other 3 variables were already there, I didn’t add them)
  7. Select the Due Date field with your cursor:
  8. On the Options tab in the ribbon, click Conditional Formatting, and choose Show Content.
  9. On the Condition Criteria screen, click the Advanced button.
  10. Type $FilterParam!=”  then click OK and click OK again.  This means that if the task admin parameter is not blank, it will show the content you selected, which is the date editable field.
  11. With the cursor still in the Due Date right column, select the Due Date field in the Data Source Details pane on the right.  Click Insert Selected Fields As… choose Formatted… and choose DateTime.
    031512_1800_ListFormFie5
  12. Now you’ll see a “read only” date on your form.  It’s time to create a rule that will show this field when the logged in person is not a task admin.  Note that with conditional formatting, you do have the ability to select an entire row if you want, and just show/hide the whole thing.
    Select the new date you just added to the form.  Click the Conditional Formatting button and choose Show Content.  Repeat steps 9 and 10, except this time don’t put an exclamation mark (!) in the formula.
  13. Save your changes.
  14. Click the F12 button on the keyboard to open the page in the browser.  Be sure to flip back over to SharePoint Designer and CLOSE that aspx form.
  15. In the browser, click the Page tab.  Click the Edit Page button.
  16. Click the big white section on the page that says Add a web part.  Add the Single Item list that you created at step 1.
  17. For the Single Item web part, in the Toolpane, expand the Advanced section. In the Target Audiences box, type or select the name of the group of people that you DO want to be able to edit the task due date. Click OK.
  18. Click the black arrow at the top right of the Task Admins web part, and choose Connections.  Choose Send Row of Data to, and choose your Task web part.
  19. Choose Get Parameters From, and click Configure.
  20. The Provider field name is “Title”, and the consumer is the FilterParam.  Click Finish.
  21. Now that the web parts are connected, and you’re seeing the editable Due Date field if you’re in the SharePoint group that you used in step 17, it’s time to hide the Single Item web part.  In the web part toolpane for Single Item, expand the Layout section.  Check the box next to Hidden, and click OK.
  22. On the page tab at the top, click Stop Editing.

Go ahead and test the solution.  Navigate to your Tasks list as you normally would, and Edit one of the tasks.  You’ll notice that if you’re in the list of task admins (or whatever SharePoint group you used at step 17), you’ll see the Due Date as editable.  Then, take yourself out of that SharePoint group, and then when you edit a task, you won’t be able to change the due date.

Technorati Tags: SharePoint,data view web parts,web parts,parameters,forms,fields,list form

18 comments

  • As a non-developer myself I really appreciate this creative approach – real thinking outside the box.

  • Hi Laura,

    I blogged about how to achieve column security level dynamically extending the ListFieldIterator class. This is just another option if we do not want to use Infopath or if our custom security requisites are more complex and specific. The ListFieldIterator MSDN article is not so clear and this post helped me and other people to clarify the topic.

    http://www.helpmeonsharepoint.com/2012/02/column-security-level-in-sharepoint-do.html

  • Is it necessary to set the Parameter Source to “Query String” or could you leave that value as blank?

    I have not tried this but it would seem that anyone who typed “?Filter=1” at the end of the URL address would be able to see the hidden fields. Whereas, if you did not set the Parameter Source you could avoid this possibility and still be able to target the parameter from the web part connection.

  • Dan,
    I don’t know, the query string part may not be necessary, good point. I guess a user that was a serious hacker would have to know the name of the parameter to do something like that. 😉

  • Everything goes as planned until I perform the last step connecting my list webaprt to the form. Once I submit the parameters connection, my screen goes to an error page that only allows me to go to the web part maintenance page and reset the web parts to not be connected.

    Any idea why this would be happening?

  • Hi Steven,
    I can’t imagine what the problem would be. I recommend testing this by creating a completely new custom list with just one or two fields, and try this solution with it. Then, you’ll know if the error is related to one of your fields or something. Also, you could get your correlation ID from your error and dig through the SharePoint ULS logs.

  • can something like this be done with SP 2007?

  • L01… yes, I stated that in big purple letters at the very beginning of the post.

  • Hi Laura – great post. Question – once done, if you have the ability to edit the fields, both the editable and the read-only text value shows when the item is put in edit mode. Is this normal or did I miss something?

  • Rhona,
    Yes, step 12.

  • Himanshu Mishra

    Exactly what i needed. Thanks

  • Awesome article using sharepoint features. I have similar reqt and glad i found ur article.

  • Hi Laura

    Im using SP2007, but I couldn’t identify Step 3 and Step 5 onwards.

    I tried using the method you mention over here – http://www.sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?List=daba3a3b%2Dc338%2D41d8%2Dbf52%2Dcd897d000cf3&ID=3&Web=dbb90e85%2Db54c%2D49f4%2D8e97%2D6d8258116ca0

    however, when the user click on the “new” action, it lead them to error page. me, as the admin do not have issue clicking on “new” action. can you advise how do I resolve this?

    thanks

  • I’d have to know what the error page says before I could troubleshoot that.

  • Has Part 3 been posted yet? I can’t find it. Thanks.

  • Apparently I never wrote a part 3, but I did a video on another way to do this in 2010/2013: https://www.youtube.com/watch?v=cC-PlAg-SuI

  • Laura – Have you ever done this for a calendar list? Specifically where the field you’re attempting to show/hide is a checkbox (All Day Event)?

    • No, I haven’t. I do know that calendars are a different beast, and the way they store data in those all-day and “recurring” fields are different than normal fields.

Leave a Reply