Tags

, , , ,

Recently, I have discovered some performance issues with custom forms created with SharePoint Designer. Mysteriously, form was slow even for adding new records to the list.
Looking into the code created by SharePoint Designer, I discovered that new form was based on SPDataSource with ListItem mode set and CAML was getting all data from the list.

<SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ContentType&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Item&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" ID="Service_x0020_List_x0020_Marcom1">
<SelectParameters>
         <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="" Name="ListItemId" />
        <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{036D8075-3258-4DA2-8804-52897332DD3E}" Name="ListID" />
</SelectParameters>
</SharePoint:SPDataSource>

Analyzing CAML select command, I realized SPDataSource is getting all rows from Item content type. For a custom list this probably means all rows. So, I decided to change it.

<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;Value Type=&quot;Counter&quot;&gt;{ItemId}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" ID="Service_x0020_List_x0020_Marcom1">
<SelectParameters>
         <WebPartPages:DataFormParameter ParameterKey="ItemId" PropertyName="ParameterValues" DefaultValue="" Name="ItemId" />
        <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{036D8075-3258-4DA2-8804-52897332DD3E}" Name="ListID" />
</SelectParameters>
</SharePoint:SPDataSource>

What I changed:

  • SPDataSource was set to List mode from ListItem.
  • CAML was changed and filter was applied on ID field.
  • ListItemId parameter was changed to another one. I called it ItemId, but you can choose different names. Is also a good idea not to bind this parameter to ID query string.

Applying this changes results in speed increase. Try it and you will see. Don’t let SharePoint Designer control you.

Advertisements