Ram Prasad Meenavalli
 
 

Issues with migrating custom field types to SharePoint Server 2013

Published on 10-Jun-2015 | Comments

Custom field types are one of those components which cause issues when migrated to SharePoint Server 2013 from its earlier versions. Following are the basic troubleshooting steps to be validated

  • Use the 'Import SharePoint 2010' template available in Visual Studio 2012 to upgrade the custom field types solution.
  • Make sure the SharePointProductVersion is set to 15.0 instead of 14.0 in the manifest file for the Solution element
  • The .net Framework target should be 4.5 for the TargetOfficeVersion of the project files.
  • Make sure the references to user controls or files are updated to refer the 15 hive (eg., /_layouts/15/controltemplates/...)

Even after verifying these, the custom field types were not working in our environment. The field was present in the lists and the migrated data was visible in the list views. Also, the field control was working in 2010 site/s (which are migrated to SharePoint 2013). But, after the visual upgrade the field control was not rendering in the new and edit forms. After some research I found that it's because of the change in the control rendering mechanism in SharePoint 2013.

The rendering design of custom field types has a significant change in SharePoint Server 2013, compared to earlier versions of SharePoint. For versions prior to SharePoint 2013 we had to create a custom field control (a user control) and this is bound to the field type using its FieldRenderingControl property. Usually this property is overridden and the custom user control is instantiated and returned to the pipeline. Sample snippet below

public override BaseFieldControl FieldRenderingControl { [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] get { BaseFieldControl fieldControl = new CustomFieldControl(); fieldControl.FieldName = this.InternalName; return fieldControl; } }

SharePoint 2013 has changed the display behavior of custom field types with Client Side Rendering mechanism. The fields now have a property called JSLink, using which we can refer a custom js template to define how the control/s render for custom field types. After some research I found that whenever SharePoint finds a JSLink property, it ignores the FieldRenderingControl property and as a result our custom field control is never rendered. To force the rendering of the custom field control, we have to override the JSLink property and return an empty string for this property. The final code snippet should like below

public override string JSLink { get { try { var mode = FieldRenderingControl.ControlMode; return string.Empty; } catch (Exception) { // Reference to custom JS file if //user control is not found return "customtemplate.js"; } } set { base.JSLink = value; } }

With this, the custom field control should be loaded and field type should work on the visually upgraded SharePoint site.

Author

View Ram Prasad Meenavalli's LinkedIn profile

Ram Prasad MCITP,MCTS,MCPD
SharePoint Technology Evangelist

 

 

Comments