Reverse-engineer SharePoint fields, content types and list instance—Part4
In first 3 posts of this series, I demonstrate how to reverse engineer SharePoint fields, content types. In this post I will show you how to configure the fields, e.g. how to make the field a required filed, how to show the field only in the NewForm or EditForm. You can download the source code here.
I have modified my solution a little bit, instead of creating a generic list instances for employee and department and configuring the content type for the list using feature receiver, I have created 2 List Definition based on the 2 content types employee and department as shown blow. Before trying to make the field a required field in a list, you need to understand that you can set the field as required field in 3 levels, site column level, site content type level and list content type level from the SharePoint object model as well as SharePoint user interface. You need to make sure you set it as the lowest level which is list content type level.
1. Make the DepartmentManager field a required field, you need to add the Required=”TRUE” to the ContentType definition in Elements.xml under Resources as well as in the list definition schema (Schema.xml under DepartmentDefinition) Note: TRUE is case sensitive, so True or true does not work, it is the same for FALSE, so False and false will not work.
2. To make the lookup field a required field. You need to set the required field on the SPFeildLink type as highlighted below.
3. To make DepartmentManager field to show on the new form but not edit form, you need to perform the following. (TRUE and FALSE are case sensitive)
4. To make the lookup field to show on the new form but not edit form, you need to set the SPFieldLookup type as below because in the SPFeildLink it only has ShowInDisplayForm property: