4

The Export to a CSV file function of Sitecore Forms seems to set the field sort order randomly. Does anyone know how I might set a specific field sort order? Thanks

6

SqlFormDataProvider

The order of the field is basically the order in which the fields were created. The genesis of the export is the Sitecore.ExperienceForms.Client.Controllers.ExportDataController. And this calls into the Sitecore.ExperienceForms.Data.SqlServer.SqlFormDataProvider provider.

The SQL that fetches the list is this.

List<FormEntry> formEntryList = new List<FormEntry>(this.SqlDataApi.CreateObjectReader<FormEntry>("SELECT {0}ID{1},{0}FormItemID{1},{0}Created{1} FROM {0}FormEntry{1} WHERE {0}FormItemID{1}={2}formItemId{3} AND {0}Created{1} BETWEEN {2}start{3} AND {2}end{3}", new object[6]

specifically SELECT {0}ID{1},{0}FormItemID{1},{0}Created{1} FROM {0}FormEntry{1} WHERE {0}FormItemID{1}={2}formItemId{3} AND {0}Created{1} BETWEEN {2}start{3} AND {2}end{3}

This just fetches them in the default SQL sort order which is the order the rows are in the table

enter image description here

The fix is to rewrite the class Sitecore.ExperienceForms.Data.SqlServer.SqlFormDataProvider, which is the implementation of IFormDataProvider. You can make this sort it any way you want, or what is possible. This class is registered in the config file App_Config\Sitecore\ExperienceForms\Sitecore.ExperienceForms.config.

<register serviceType="Sitecore.ExperienceForms.Data.IFormDataProvider, Sitecore.ExperienceForms" implementationType="Sitecore.ExperienceForms.Data.SqlServer.SqlFormDataProvider, Sitecore.ExperienceForms.Data.SqlServer" lifetime="Transient" />

The fields are incredibly dynamic

Now the real question is how would you get the sort or you want? Maybe a multilist setting or something that would allow you to do it in the editor. To me the real issue is that you can add and remove fields at will. And based on the date range you pick in your export, it fields the fields that were in place within that range. That makes it super difficult to allow you to know what fields to sort and when. Very dynamic.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.