Wednesday, July 11, 2012

Manage Visibility in List Fields Forms

This article try to help and give some hint or ideas about a topic that normally is asked by users, the ability to manage the visibility of fields in the different Form Lists.
Some users ask the Site owners if it is possible to manage the Field in the different Forms, Display some fields in the new form, other fields in the Edit Form and the same for the Display Form.

The normal answer for this request from the consultant is use the  DataView from SharePoint Designer "Customization Skills in Pages", or Powershell Script "IT Administrator" or use JavaScript code "JavaScript Skills with Webparts in the Forms Lists" to hide columns.
JS Example:

<script language="javascript" type="text/javascript">
      function HideControl() {
          var field = document.getElementById('ID control from New Form, Edit Form, Display Form');
 = "none";

To response this request, yesterday evening was playing around with SharePoint 2010 and create a new Application Page to manage the visibility of field in the Form Lists (New Form, Edit Form, Display Form).

PS: Please remember this example project was made to explore some properties in the List and how we can manage, use by your own risk. I belive there is others applications made for SharePoint 2010 that have the same behavior and my project was made in 30 minutes "I spent more time writing this article that creating the application :)) "....

The solution was created using the following tools:
  • Visual Studio 2010
  • SharePoint 2010
  • SharePoint Manager 2010 v2 (Thanks for this tool Carsten Keutmann, every SharePoint Admin or Developer should have...)

SharePoint Deployment:
  • Farm Solution 
  • ManageListPages.wsp
  • Powershell scripts
    • Add-SPSolution -LiteralPath <SolutionPath>
    • Install-SPSolution -Identity <SolutionName> -WebApplication <URLname> -GACDeployment

  • Manage List Forms
    • Scope: Web
  • Element File 
    • A new option will appear in the Ribbon (Lists, Document Library, Calendar) Tab "List > Settings > Columns visibility in form" 
    • Rights: "ManageLists" - SPBasePermissions
  • Application Page
    • This page will be Manage the field in the List Forms.

SharePoint Solution: 

Using the API Objects with SharePoint Manager we can access the Field associated to a List and view his properties and validate if they are visible or not, as shown in the image below.

  • If properties (ShowInDisplayForm,  ShowInEditForm,  ShowInNewForm) are null the fields are visible in the Forms.

How to Activate Feature "Manage List Fields Forms"
Site Actions > Site Settings > Manage site features > Manage List Fields Forms > Activate Option

When you access a List View and select the Ribbon Tab "Columns visibility in Form" this Button option will redirect to Application Page where you can manage the Visibility of the Field for the List Forms.

When we access the Application Page, we are able to see the existing status of the Fields and select the Field to manage.

This application will give option to manage the following Forms "New Form, Edit Form, Display Form".

Button "Save Field", this option will save the visibility of the field in the List Forms and display the status in the main board status.
For this example i selected the field "% Complete" and uncheck "Edit Form" to don't display in the Edit Mode.

After make this change you can access you List Forms and validate if the field are correct.
For this example open "New Item" and validate the state of the field "% Complete" is visible.

If you open the Edit option Form the field "% Complete" will not appear, as shown in the image below.

If you open the Display option Form the field "% Complete" will appear again, as shown in the image below.

If you wan to revert to old state of the field, you need to access the "Manage Form Page" and select the correct Field "% Complete" the option "Reset Field to all Forms" and change the status of that field to null.
The value null means that will be accessible to all Forms.

After the selection of this option the field will be displayed in all Forms.

I understand this is not very complex project and this can be easily be managed in the List properties, but want to show a example on how we can create some BackOffice page to manage your lists properties, in this case manage the fields, but can also be made to create/Manage other properties or create new one like  Propertie Bag, etc...

This Project example is located in the following Link.

Hope you like :)

Kind regards,
André Lage

No comments: