Issues with Exporting Form Data to CSV

Button – Export the selected form data to CSV

Recently, I encountered a bug related to the Export the selected form data to a CSV button in the Forms module in the Sitecore XP 10.2. When I tried to use this button, nothing happened, and just a message appeared. After some investigation, I discovered that there were two issues causing this problem.

Error – There is no data present for the form
1) First Bug

The first issue was related to the missing “Save Data” submit action for the form. This Submit Action is crucial as it is responsible for saving the form data to the database. Without it, the form data cannot be exported to a CSV file. Once I added the Save Data Submit Action to the form, the export functionality started saving the data.

To make sure the data is properly stored in the database, you should check the ExperienceForms database, in the tables FormEntries and FieldData, to see if there are any data:

If there’s no data, you are likely facing other errors, check out the logs and figure it out.

2) Second Bug

After being able to save the form data, I was facing this message:

Message – The list is being exported. A notification appears when the export is complete. You can continue your work.

So after a while, the message just disapeared and nothing happened.

It was related to FormsExtension, a module that allows us to extend the OOTB Form module. In the past, the client had requested customization to this module, which worked fine for its purpose, however it was breaking the code every time the export button was pressed. The bug in the code was related to an attempt to access the Context object, which does not exist in this scenario.

The Context object is an essential part of Sitecore, and it provides access to information such as the current user, the current item, and other Sitecore-specific information. However, when exporting data to a CSV file, the Context object is not available. As a result, any attempt to access it will result in an error.

Look closely at your code and look for code snippets, like these:

RenderingContext.CurrentOrNull.Rendering.Parameters["your-parameter"];

Context.Database.GetItem(path);

Context.Item.ID.ToString()

To fix this issue, I modified the code in order to address the old features and this Export button, so, the export functionality started working correctly.

The result should be:

Questions about Submit Actions? Take a look at the documentation: https://doc.sitecore.com/xp/en/users/103/sitecore-experience-platform/working-with-submit-actions.html

Have a good day! 🚀

Leave a Reply

Your email address will not be published. Required fields are marked *