Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Skennerton 17 posts 179 karma points notactivated
    Apr 12, 2024 @ 14:16
    Alex Skennerton
    0

    Custom forms workflow with Newsletter Studio

    I am trying to create a custom workflow within Umbraco forms to allow users to sign up for a mailing list in Newsletter Studio.

    The form works and the workflow runs but no information is copied into the mailing list, what am I missing?

    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Core.Persistence.Dtos;
    using NewsletterStudio.Core.Public.Models;
    
    namespace MyFormsExtensions
    {
    
        public class Subscribe : WorkflowType
        {
        public Subscribe()
        {
            Name = "Newsletter Sign-up";
            Id = new Guid("7793f98d-266f-4905-b2f2-9d27438da763");
            Description = "Add sign-ups to the mailing list";
            Icon = "icon-inbox";
        }
    
        public override WorkflowExecutionStatus Execute(WorkflowExecutionContext context)
        {
    
                RecordField? recordNewsletteremail = context.Record.GetRecordFieldByAlias("email");
                RecordField? recordName = context.Record.GetRecordFieldByAlias("name");
                RecordField? recordDistrict = context.Record.GetRecordFieldByAlias("district");
                var newsletteremail = recordNewsletteremail.ValuesAsString();
                var name = recordName.ValuesAsString();
                var district = recordDistrict.ValuesAsString();
    
            var request = AddRecipientRequest.Create(newsletteremail)
                .WithSource("Footer")
                .WithName(name)
               .WithCustomField("District", district)
               .SubscribeTo(Guid.Parse("15C21B14-2673-40E1-9730-ED04B4161DE4"))
                .Build();
    
            return WorkflowExecutionStatus.Completed;
        }
    
        public override List<Exception> ValidateSettings()
        {
            return new List<Exception>();
    
    
        }
        }
    }
    
  • Markus Johansson 1924 posts 5831 karma points MVP 2x c-trib
    Apr 12, 2024 @ 15:50
    Markus Johansson
    100

    Hi!

    Nice integration!

    You need to pass the request that is built to the INewsletterStudioService.

    var result = _newsletterStudioService.AddRecipient(addRecipientRequest);

    There is a working example here https://www.newsletterstudio.org/documentation/package/13.0.0/develop/front-end-api/

    Another thing to mention here is that it’s quite easy to add a workflow step to Umbraco Forms that will send a transactional email - quite cool for confirmations, notifications etc.

    Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft