Customize multiple choice form field value separator

Vote:
 

It is about a form containing multiple choice fields. When you submit the form - multiple choice values are saved as string separated by comma. I am trying to utilize Marketing Automation package and send form submissions to Salesforce. SF itself use semicolon as multifield value separator. Therefore integration failed in case form submission contains multi field values. 

Do we have any option to customize field value separator on Episerver side and specify alternative character?  

#200593
Jan 17, 2019 9:32
Vote:
 

I'd do a reflection on the package code using DotPeek or similar. You may find that the actor used for pushing to Salesforce has method that would allow you to override the format but that's a guess.

#200599
Jan 17, 2019 10:41
Vote:
 

Great. Thanks for idea and help Scott. Will take a look and update the ticket with some findings. 

#200623
Jan 17, 2019 15:05
Vote:
 

Hi Bogdan,

You can create a custom ActorsExecutingService(class in EpiServer.Forms package) service to modify submission data before pushing data to connectors (e.g Salesforce in your case). Don't forget to register new dependency.

I make a quick test with Campaign Connector and it works

using EPiServer.Forms.Core.Models;
using EPiServer.Forms.Core.PostSubmissionActor;
using EPiServer.Forms.Helpers.Internal;
using EPiServer.Forms.Implementation.Elements;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class CustomActorsExecutingService : ActorsExecutingService
{
    public override IEnumerable<IPostSubmissionActor> GetFormSubmissionActors(Submission submission, FormContainerBlock formContainer, FormIdentity formIden, HttpRequestBase request, HttpResponseBase response, bool isFormFinalizedSubmission)
    {
        var allActors = base.GetFormSubmissionActors(submission, formContainer, formIden, request, response, isFormFinalizedSubmission);
        var returnActors = new List<IPostSubmissionActor>();

        foreach (var actor in allActors)
        {
            // if not Marketing Automation actor, add to returnActors list and ignore
            if (!(actor is MarketingConnectorActor)) 
            {
                returnActors.Add(actor);
                continue;
            }

            var allFormElements = formContainer.Form.Steps.SelectMany(st => st.Elements);
            var choiceAndSelectionElements = allFormElements.Where(x => x.SourceContent is ChoiceElementBlock || x.SourceContent is SelectionElementBlock);
            var marketingActor = actor as MarketingConnectorActor;

            foreach (var element in choiceAndSelectionElements)
            {
                var fieldName = element.SourceContent.GetElementName();
                //if (element.SourceContent is SelectionElementBlock)
                //{
                //}

                // get the selected value from submission data
                var selectedValue = marketingActor.SubmissionData.Data[fieldName]?.ToString();
                if (!string.IsNullOrWhiteSpace(selectedValue))
                {
                    // replace comma with semicolon 
                    marketingActor.SubmissionData.Data[fieldName] = selectedValue.Replace(",", ";");
                }

            }

            returnActors.Add(marketingActor);
        }

        return returnActors;
    }
}

The data is sent to Campaign Connector system

Hope this help !

#200636
Edited, Jan 18, 2019 9:26
Vote:
 

Works like charm. Thanks a lot Quan!

Worth to mention that MarketingActor resides in  separate nuget package (EPiServer.Marketing.Automation.Forms). 

#200725
Jan 23, 2019 14:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.