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:

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.
    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 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.
    031512_1800_ListFormFie6
  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

Advertisements

16 comments

  • 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.

    Like

  • 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

    Like

  • 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?

    Like

  • I couldn’t find step 18.
    Any idea?

    Like

  • 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.

    Like

  • 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.

    Like

  • 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.

    Like

  • 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.

    Like

  • I’m currently using this guide in order to hide an approval field that can only be modified by Business Leads.

    It is a Yes/No Checkbox Field

    I guess I am missing something.

    In step 11 I am selecting Item(s) and am getting a weird number 1 that appears at in the first row of my forms table.

    Any push in the proper direction is appreciated.

    BTW great Sharepoint stuff

    Like

  • Laura,

    I am having problems connecting the web parts in 2010. When doing step 19 my Connection Settings say “No Consumer Schema”. All the other steps seemed to have worked fine. Any help would be greatly appreciated.

    Thank you,

    Like

  • Marcus,
    That yes/no field is stored as a 1/0 in the list, I believe. So, a 1 would mean Yes. You could get around this by creating conditional formatting. Type the word Yes, and the word No. Select Yes and create a condition to only show this word if is equal to 1. Do the opposite for No.

    Dan,
    I’ve only seen this happen when there’s no parameter specified in the consumer web part. Step 6 is where you create the parameter.

    Like

  • Great stuff Laura. I used this concept on a xslt list view (setting it to default view) so I could hide actual certain metadata (fields) based on whoever was popluated in a people picker column called ‘admins’ for the list. This is a great way to hide individual columns based on user without code.

    Like

  • Hi Laura,
    I can’t get this to work in SP/D 2007. I assume the additional parameter called “ID” is with Source None and also needs to be added to the DFWP? Can you please let me know where to apply the filter “ID is equal to {IDparameter]?
    As soon as I throw the exported DFWP and the TaskAdmin web part on the Page and Edit the Current View of the TaskAdmin web part (Settings – List Settings – Views – Filter -> Person is equal to [me]), the DFWP and the hidden default editform web part disappear and send row of data to in TaskAdmin web part is greyed out. Any help would be greatly appreciated.
    Thank you.

    Like

  • Ronald,
    You open up the form web part in SPD, click your mouse into the form, and then click Parameters in the ribbon. To add the filter, click “filters” in the ribbon.

    Like

  • Hi,

    I’m trying to use this to make it so managers can edit their teams timetables which are in calendar view, but their teachers can add comments to the events, but not edit the event details. I know the calendar view itself is not compatible with the connections (18. in your instructions), but can I do it on a different view I’ve made in datasheet, or will it only work if the original list is set up in datasheet?

    If I can get this to work I will be so happy!

    Many thanks

    Like

  • Hi Hazo,
    This just can’t be done on an actual calendar view or datasheet views, but it can be done on the forms that they fill out, like newform, editform.

    Like

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s