1

I am using sitecore 10.3 and working with sitecore forms "Send Email Compaign Message" Action. it is working and e-mails are sent when I select "Email" Field but it is not working when I select "DropDownList" Field as below enter image description here

I need to send to different admin E-mails based on value of "DropDownList" value that selected. so i added the E-mail adresses as values in dynamic datasource

enter image description here

but when I submit the emails are not sent. I tried to add token for dropdownlist to see its value and it is coming in array like ["[email protected]"]

I do know if this the error or what, any ideas how to fix this ??

3
  • You need to write custom logic to fetch the data from the drop-down list Commented Jan 23 at 2:18
  • ok but how to send it to "send email compaign message" action, or you mean to create custom action to send mail Commented Jan 23 at 9:05
  • you need to create a custom email action to get the details(email id) from the dropdown list. Commented Jan 23 at 10:09

1 Answer 1

1

you need to override GetFieldValue to return the email values as ";" separated

class FormsFieldValueResolver : Sitecore.EmailCampaign.Cd.Actions.FormFields.FormsFieldValueResolver
{
    public override object GetFieldValue(IViewModel fieldViewModel)
    {
        Condition.Requires(fieldViewModel, nameof(fieldViewModel)).IsNotNull();
        if (fieldViewModel is TextViewModel textViewModel)
            return textViewModel.Text;
        else if (fieldViewModel is DropDownListViewModel listViewModel)
            return string.Join(";", listViewModel.Value).Trim(';');
        return fieldViewModel.GetType().GetProperty("Value")?.GetValue(fieldViewModel);
    }
}

donot forget to use your new implementation through Dependency Injection

    public class ServiceConfigurator : IServicesConfigurator
{
    public void Configure(IServiceCollection serviceCollection)
    {
        Condition.Requires<IServiceCollection>(serviceCollection, nameof(serviceCollection)).IsNotNull<IServiceCollection>();
        serviceCollection.AddSingleton<IFormsFieldValueResolver, [YourNameSpace].FormsFieldValueResolver>();

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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