Sunday, 17 September 2017

WFFM : Customizing export form data to excel functionality

Leave a Comment
In previous blog posts, I have explained how to create custom SQL provider and custom save to database action to store form data into SQL database. If you’re interested to know the context of the customization, checkout this blog post. In this blog post, I’ll explain how to customize export form data to excel functionality so that form reports include user’s browser information.

Environment Detail

Sitecore 8.2 update 5 (CMS only mode), Web Forms for Marketers 8.2 rev. 170807

Implementation

I’ve decompiled Sitecore.WFFM.Services.dll assembly to find out the code which invokes export form data to excel functionality.

It seems that we cannot override few methods inside of Sitecore.WFFM.Services.Pipelines.ExportToExcel.ExportFormDataToExcel class. So I created a duplicate copy of this class and added my custom logic to include user’s browser information into form reports.

Add a patch config file to configure custom export to excel functionality:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
       <!--EXPORT TO EXCEL--> 
      <exportToExcel>
        <processor patch:instead="processor[@type='Sitecore.WFFM.Services.Pipelines.ExportToExcel.ExportFormDataToExcel, Sitecore.WFFM.Services']" type="Website.WFFM.Pipelines.CustomExportFormDataToExcel, Website" />
      </exportToExcel>
    </pipelines>    
  </sitecore>  
</configuration>
That's it! Comments and suggestions are most welcome. Happy coding!
Read More...

WFFM : Create custom Save to Database Action

Leave a Comment
In last blog post, I have explained how to create custom SQL provider to store form data into SQL database. If you’re interested to know the context of the customization, checkout the last blog post. In this blog post, I’ll explain how to create a custom save to database action.

Environment Detail

Sitecore 8.2 update 5 (CMS only mode), Web Forms for Marketers 8.2 rev. 170807

Implementation

  1. Create a new SaveToDatabaseAction class and inherit WffmSaveAction class.
  2. Write custom logic to add new FieldData to form field list dynamically while saving form data.

  3. Build the code and deploy assembly in bin folder of your Sitecore instance.
  4. Navigate to Sitecore content tree and create a new Save To Database save action under /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions node.
  5. Add a config patch to specify WFFM connection string.
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
      <sitecore>
        <settings>
          <setting name="WFM.ConnectionString" value="wfm" set:value="wffm" />
        </settings>
      </sitecore>  
    </configuration>
  6. Select the relevant WFFM form and add Save To Database action in Save Actions.

  7.  Select the relevant WFFM form and in the Submit section, un-check Save Form Data To Storage checkbox so that form data won’t get saved multiple times into the SQL database.
  8. Publish Sitecore related changes.
In next blog post, I’ll explain how to customize export form data to excel functionality so that form reports include user’s browser information. Comments and suggestions are most welcome. Happy coding!
Read More...

WFFM : Customizing SQL form data provider

Leave a Comment

Requirement

I’ve got a task where I have to save user’s browser information (Browser name and version) into Sitecore WFFM SQL database as part of the every WFFM form submission. Website support team would like to know the user’s browser that is being used for accessing the production site, so that they don't have to request this information while troubleshooting any issues the user has reported via the Feedback/Troubleshooting Contact Us form.

Environment Details

Sitecore 8.2 update 5 (CMS only mode), Web Forms for Marketers 8.2 rev. 170807

Implementation

I’ve decided to customize WFFM save to database functionality and add new FieldData to form field list dynamically while saving form data. This new FieldData will consist user’s browser information (Browser name and version). This implementation can be achieved by below three ways:
  1. Customizing SQL form data provider
  2. Create new save to database action
  3. Create a custom field. 
We have to also modify export form data to excel functionality so that form reports include user’s browser information. In this blog post, I’ll explain how to create custom SQL provider to store form data into SQL database.

WFFM Configuration

In the \Website\Data folder of your Sitecore instance, attach the Sitecore_Wffm.mdf database to the SQL Server, and add a connection string with the name “wffm” in the ConnectionStrings.config file, located in the \Website\App_Config folder.
<add name="wffm" connectionString="Data Source=(local);Initial Catalog=instance_name_wffmDB;Integrated Security=False;User ID=sa;Password=12345"

Customizing SQL form data provider

  1. Create a new CustomSqlFormsDataProvider class and inherit SqlFormsDataProvider class.
  2. Write custom logic to add new FieldData to form field list dynamically while saving form data.

  3. Add a config patch as below to configure CustomSqlFormsDataProvider.
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
      <sitecore>
        <wffm>
          <analytics>
            <formsDataProvider patch:instead="*[@ref='/sitecore/wffm/analytics/analyticsFormsDataProvider']" ref="/sitecore/wffm/analytics/customSqlFormsDataProvider"/>
            <customSqlFormsDataProvider type="Website.WFFM.Providers.CustomSqlFormsDataProvider, Website">
              <param name="connectionStringName">wffm</param>
              <param name="settings" ref="/sitecore/wffm/settings"/>
              <param name="connectionProvider" ref="/sitecore/wffm/analytics/connectionProvider"/>
            </customSqlFormsDataProvider>
          </analytics>
        </wffm>
      </sitecore>  
    </configuration>
  4. Select the relevant WFFM form and in the Submit section, select Save Form Data To Storage checkbox.
  5. Publish Sitecore related changes. Build the code and deploy assembly in bin folder of your Sitecore instance.
In next blog post, I’ll explain how to create a custom save to database action. Comments and suggestions are most welcome. Happy coding!

Update:

After publishing this blog post, I had a nice fruitful conversation with Sitecore MVP Kamruz Jaman regarding this implementation. If you are not already using custom SQL provider in your solution then prefer to create a custom field to handle above scenario. Nevertheless, this WFFM blog post series will give you fair idea about how to customize SQL form data provider and export form data to excel functionality.

Read More...

Saturday, 9 September 2017

WFFM upgrade issue : List field values are empty in Form Designer

Leave a Comment
Recently, I was involved in Sitecore upgrade project and encountered few issues. In this blog post, I am going to explain the issue related to WFFM module upgrade. 

Issue

We have upgraded to Sitecore 8.1 Update 3 CMS only mode and upgraded WFFM module as well. After upgradation, we are seeing an issue in WFFM form designer. The problem is related to WFFM Radio List field or Drop List field in Form Designer where we are no longer able to see the list items which were present there before the upgrade.  See below screenshot:


Radio List field or Drop List field related item data was saved in Parameters field as you can see from the below  screenshot:


I’ve tested this functionality on vanilla Sitecore 8.1 update 3 + WFFM instance. After my initial troubleshooting, it seems that Sitecore WFFM 8.1 is now using Localized Parameter field to display the items in Radio List field or Drop List field.


WFFM 8.1: Whenever we create new form item, Radio List field or Drop List field value gets stored in Parameters and Localized Parameter field. Radio List field or Drop List field is using Localized Parameters field to show those values in the Form Designer

I’ve reached out to Sitecore support team and they have registered this behavior as a bug in the current version of the WFFM module. To track the future status of this bug report, please use the reference number 75227.

Since WFFM 8.0 Localized Parameters are used for the purpose of localization. There is a specific piece of code which was supposed to be executed as post upgrade action, but was not invoked. This code was supposed to copy value from Parameters fields to Localized Parameters to keep this upgrade transition seamless. Since, this code did not execute, intended didn't happen and we have faced the issue. This behavior is not reproducible in WFFM 8.2.

Solution

  1. As a workaround, you can manually copy the value from the Parameters field to the Localized Parameters field in your Radio List field or Drop List field items that are located under form items.
  2. If you have many forms/fields you can ask Sitecore support to provide a script that you can run against your Sitecore instance which will copy the value from the Parameters field to the Localized Parameters field. You have to run the given .aspx page and enter the full path to the folder where your web forms are located (e.g. “/sitecore/system/Modules/Web Forms for Marketers/Website” or “/sitecore/system/Modules/Web Forms for Marketers/library”) to the textbox field. Click the “Update” button. This will updated web forms in master database.
    I’ve modified the support patch to meet our requirements:
    • Web forms are located at many different places in the Sitecore content tree. We have to find out full path for every web form and repeat the update process for every web form. This process seems cumbersome. Though it is possible to specify common root for all form items, given script is designed to work on items from specific templates only. But it will be more expensive to traverse whole tree compared to specific form folders. I’ve modified the script to find out all the referrers of form template (/sitecore/templates/Web Forms for Marketers/Form {FFB1DA32-2764-47DB-83B0-95B843546A7E}) using Sitecore link database. You can also use Sitecore Powershell Extensions to achieve same output.
    • We want to avoid publishing operation as it may publish unwanted or work in progress changes to web database and make those changes live. In this case, I’ve modified database name in the script to modify web form field items in web database as well. So, there will not be a need to publish these changes from master to web database. However, please ensure to run script on master as well so that any subsequent publish does not overwrite your changes in web database.
Comments and suggestions are most welcome. Happy coding!
Read More...

Sunday, 3 September 2017

Sitecore - Get items associated with email reminder task

Leave a Comment
In Sitecore, you can schedule to send an email reminder to one or more users. Occasionally an author may wish to be reminded of something regarding the item he is working on. Sitecore Reminders are made just for that. They also make the Administrator's work easier, by providing a suitable way of notifying Editors and other staff members about changes needed to be made. Reminder settings for an item are set in the Tasks section:


You can also set reminder settings for an item by clicking on Set Reminder in Review Strip of Sitecore Content Editor Ribbon.


Recently I have stumbled upon a situation where I have to find out all the items which are configured to use Email Reminder task.  Execute below SQL query on Core database to get list of item ids which are configured to use Email Reminder task.
SELECT ItemId FROM Tasks WHERE taskType='Sitecore.Tasks.EmailReminderTask,Sitecore.Kernel'
Comments and suggestions are most welcome. Happy coding!
Read More...