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

Three years ago, I wrote a blog post called Displaying SharePoint Fields by Permission Level.  This one has the highest amount of hits, but it is an imperfect solution.  One of the most common questions that was asked was to see if there's a way to show or hide fields in an ASPX form based on who the logged in user is, as opposed to according to permission level.

This is going to be a three part blog:

  • Part 1: Using an ASPX form, with a SharePoint list of certain people who will be allowed to edit certain fields
  • Part 2: Using an ASPX form, with a SharePoint group of people
  • Part 3: Using an InfoPath form, with a SharePoint list or group of people

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 solution in part 1 can be done with any version of SharePoint: MOSS, WSS 3.0, SharePoint 2010, and Foundation, and even SharePoint Online with Office 365.

  1. Create a custom list on your site, just to keep the list of people who are authorized to edit the certain fields in your form.  I'll call it "Task Admins".  Create a field called "Person", as a people field.  Add a few people to the list.
  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 TaskAdminParam, select Query String, and type TaskAdmin 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 $TaskAdminParam!=''  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 Task Admins list that you created at step 1.
  17. For the Task Admins web part, in the Toolpane, click Edit the Current View.  Scroll down to the Filters section, and set it so that Person is equal to [me].  Click OK.
  18. On the Page tab, click Edit Page again.  Click the black arrow at the top right of the Task Admins web part, and choose Edit Web Part.  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 "Person", and the consumer is the TaskAdminParam.  Click Finish.
  21. Now that the web parts are connected, and you're seeing the editable Due Date field if you're in the list of admins, it's time to hide the task admins web part.  In the web part toolpane for Task Admins, 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, you'll see the Due Date as editable.  Then, take yourself out of the list of Task Admins, 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

Sabin

Laura,
 Why does Date and Time Control Display Values in this format 2012-03-01T05:00:00Z. How to I adjust this to just display as 2012-03-01.

Any Help would be appreciated.
 on 3/16/2012 3:05 PM

uspepper

Hi Laura,
I followed the guide, however on the step 20 the "TaskAdminParam" is not shown in "Comsumer Field Name", what could I do wrong? Thanks
 on 3/21/2012 7:30 PM

unequal

Hi Laura,

I can't seem to get past step 4? Everytime I click on the form to open it, it loads and then I get a Microsoft error and SharePoint designer restarts.

Any idea what could be the cause?
 on 3/28/2012 4:43 PM

Wendy

I couldn't find step 18.
Any idea?
 on 4/5/2012 3:08 AM

Chris

Wendy, I had that problem and found that in order to see the option for "Send Row of Data To", you had to first go into "Edit Web Part" mode.
 on 4/10/2012 4:23 PM

Laura

Sabin,
In step 11, did you insert it as DateTime format?  That's why I did it that way, to avoid the ugly formatting.

uspepper,
Did you do step 6?  You would have had to create the parameter there in order for it to show up in the consumer web part.

Chris, good point.  I'll edit it.
lauraNo presence information on 4/12/2012 10:48 PM

Todd

Hi Laura,

I know that things are a bit different in WSS 3.0 compared to your example in SPF 2010. I'm pretty handy with SPD 2007 and have followed the instructions to a T. One thing I notice is that as soon as I create the parameter, my fields in the form disappear unless I select the option to show with sample data on the menu. not sure if this is expected behavior. The other thing I notice is that I can add TaskAdmin webpart to the Edit form in the browser using the toolpaneview=2 technique however, I cannot connect the web parts. The only way that I have been able to connect the web parts is when I add the TaskAdmin part using SPD 2007. After adding it in SPD, I can connect them and apply the filter but the end result does not work. Is there anything that I am missing or caveats to doing this in WSS 3.0? I do have an SPF 2010 farm built that I will be migrating in the next couple months to but I'd like to get this working on WSS 3.0 before then if possible.
 on 5/25/2012 9:50 AM

Laura

Todd,
Yes, it is expected behavior for the field to disappear when you create the parameter.  For your edit form, though, You'll have to create a data view web part, then in the data details toolpane in sharepoint designer, select your multiple fields, and click "insert fields as... single item form".  Then, do everything you need to do in your web part per all the instructions in here.  In addition though, you'll need to create a parameter called "ID", and add a filter so that "ID is equal to {IDparameter].  Export the web part. Go to your normal "editform" page in the browser, and do the toolpaneview trick to add this new custom web part to that page, and then hide the default editform web part.  THEN you'll be able to connect the web parts.

lauraNo presence information on 6/13/2012 10:45 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