0

We are having an issue getting any custom save action to fire from a form in the CD environment on Sitecore 8.2 Update 6. There are no errors of any kind in the logs. This is not an issue in our local development instances or the CM. I suspect consequently this is a configuration issue particular to a CD environment (possibly something in the SwitchMasterToWeb.config). If anyone has had a similar issue I would love to hear about it!

Module-wise aside from WFFM we are using the Powershell module and SXA, but nothing else.

The basic signature of the class and custom save action are as follows:

public class CustomFormSubmit : ISaveAction 
{

    public CustomFormSubmit()
    {

    }

    public void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data)
    {
        Process(adaptedFields);
    }

    public FormSubmissionResponse Process(AdaptedResultList adaptedFields)
    {
        FormSubmissionResponse result = new FormSubmissionResponse
        {
            Data = "Success",
            Status = "200"
        };

        try
        { 

        }
        catch(Exception e)
        {
            result.Data = "Error";
            result.Status = "500";
            result.Message = e.Message;
        }

        return result;
    }

    public ID ActionID { get; set; }

    public string UniqueKey { get; set; }

    public ActionType ActionType { get; private set; }

    public ActionState QueryState(ActionQueryContext queryContext)
    {
        return ActionState.Enabled;
    }

}
  • Have you followed the install guide and CD config guide to ensure the settings are correct? sitecore.stackexchange.com/a/4354/135 – jammykam Mar 10 '18 at 2:46
  • Yeah, unfortunately for us, all of that has already been observed and is correct. – David Hake Mar 10 '18 at 12:22
  • Can you post the outline of code for your save action, e.g. method signature, which class you have inherited from. I've seen this issue before but need to see the code. – jammykam Mar 10 '18 at 15:56
  • Added the outline of the code of the save action above. – David Hake Mar 11 '18 at 20:11
1

The issue is you have not set the ActionType of the Save Action, you have the properties implemented that meets the requirements of the interface but it has no value set.

This runs locally and on your CM instance since the Save Action runs immediately, but when the form is submitted the CD server the action is run actually run via the Event Queue on the CM server. This is the default setting for Save Actions. Since the Action Type is not set the save action fails to run.

One option is to mark the Save Action as being a Client Action which will force it to run immediately on the CD server. Whilst this may work, most people enable this blindly without much understanding of the issue. This may or may not be a good idea depending on the save action, what it is doing, long running operations etc. The benefit of running via the Event Queue is that Save Action being executed is deferred and run later by the CM instance, essentially allowing Async save actions (useful for long running or slow external service calls without delaying the user feedback).

The correct way to resolve this is to set the ActionType in your constructor:

public CustomFormSubmit()
{
    this.ActionType = ActionType.Save;
}

But it is even simpler to inherit from WffmSaveAction:

public class CustomFormSubmit : Sitecore.WFFM.Actions.Base.WffmSaveAction
{
    public void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data)
    {
        Process(adaptedFields);
    }    
    ...
}

This inherits and implements the correct interfaces and also sets the ActionType property in the base constructor to ActionType.Save. Your save action should now execute correctly on CM and CD instance, and regardless of whether the Client Action has been checked. By inheriting from this class you only need to provide the implementation of the Execute() method and not add properties for the rest of ISaveAction so it is a much cleaner implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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