Skip Ribbon Commands
Skip to main content

Laura Rogers @WonderLaura

:

Quick Launch

Laura Rogers @WonderLaura > Posts > List Form Fields–Show/Hide For Certain People: Part 2
Hi everyone,
My blog now has a new URL!
You can now find me at http://www.wonderlaura.com
March 16
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.

  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

Comments

Dave Paylor

As a non-developer myself I really appreciate this creative approach - real thinking outside the box.
 on 3/16/2012 7:19 PM

Daniel Hinojo

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
 on 3/17/2012 2:06 PM

Dan Kreitz

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.
 on 3/22/2012 9:53 AM

Laura

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.  ;-)
lauraNo presence information on 4/12/2012 10:51 PM

Steven

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?
 on 5/3/2012 2:26 PM

Laura

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.
lauraNo presence information on 5/25/2012 1:10 PM

L01$Lan3

can something like this be done with SP 2007?
 on 6/14/2012 9:51 AM

Laura

L01... yes, I stated that in big purple letters at the very beginning of the post.
lauraNo presence information on 6/27/2012 9:57 PM
​I have disabled any new comments on this, because my blog has moved to a new site.  Please go here: http://www.wonderlaura.com
RSS FeedFacebookYouTube
 

 Our Books for End Users