Create a pipeline processor to convert form data in a custom personalization token
You can set up EXM to initiate an automated email campaign once the customer has completed and submitted a form from a site. However, you might want to transform the original form field value to a different format for use as a custom personalization token in the rendered email message.
In the following example, the pipeline processor transforms the value of a check box list field and renders it as a list of comma-separated values. You can use the same logic for any type of form control.
To implement a new pipeline processor:
-
Implement a
TransformCheckboxList
processor that checks for theCheckBoxListViewModel
field and transforms the original value of the field from aList<string>
to a comma-separated string and sets theTransformedTokenValue
property value:RequestResponsec#public class TransformCheckboxList : Sitecore.EmailCampaign.Cd.Pipelines.TransformFormsCustomToken.ITransformFormsCustomTokenProcessor { public void Process(Sitecore.EmailCampaign.Cd.Pipelines.TransformFormsCustomToken.TransformFormsCustomTokenArgs args) { if (args == null) { throw new ArgumentException(); } if (args.Field is Sitecore.ExperienceForms.Mvc.Models.Fields.CheckBoxListViewModel checkBoxListViewModel) { List<string> checkboxListValues = checkBoxListViewModel.Value; args.TransformedTokenValue = string.Join(", ", checkboxListValues); } } }
-
Patch the Sitecore configuration to include the processor implemented in the
transformFormsCustomToken
pipeline:RequestResponsexml<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore role:require="Standalone or ContentDelivery"> <pipelines> <group groupName="exm.sendEmailSubmitAction"> <pipelines> <transformFormsCustomToken> <!-- Transforms the checkbox list field value from a List<string> to a comma separated string --> <processor type="Sitecore.EmailCampaign.Samples.FormsIntegration.Pipelines.TransformFormsCustomToken.TransformCheckboxList, Sitecore.EmailCampaign.Samples.FormsIntegration" /> </transformFormsCustomToken> </pipelines> </group> </pipelines> </sitecore> </configuration>