3

I'm trying to implement custom submit action in Sitecore 9 Forms according to the guide, but found the problem with Tracker.Current which is null while accessing from SubmitActionBase.

Tracker is fine in other areas (e.g. while accessing from view controller). If I call Tracker.StartTracking(); inside the action then Tracker.Current is ok as well.

Additional conditions:

  • form is ajax enabled
  • save action is called on "Next" navigation step, not on "Submit"

Is this expected behaviour in Forms submit action?

Here's part of the code:

public class UpdateContact : SubmitActionBase<UpdateContactData>
{
    public UpdateContact(ISubmitActionData submitActionData) : base(submitActionData)
    {
    }

    protected override bool Execute(UpdateContactData data, FormSubmitContext formSubmitContext)
    {
        //Tracker.Enabled is true
        //Sitecore.Context.Site.Tracking().EnableTracking is true
        //Tracker.IsActive is false
        var contact = Tracker.Current.Contact; //Tracker.Current is null
    }
}
1
  • This also happens in my setup. Any news about the bug from Sitecore support? Commented May 27, 2019 at 6:54

2 Answers 2

7

I received feedback from Sitecore support:

The mentioned behavior is expected because the tracker should be only triggered upon a submit as it is expensive to keep it alive after navigating to the next or previous page

So it looks that it's not a bug. Tracker is not initialized in Forms "Next" or "Previous" navigation step. To workaround it, you can either change the form to non-ajax, or initialize the tracker inside your action code:

if (Tracker.Current == null && Tracker.Enabled)
{
    Tracker.StartTracking();
}
...
//access Tracker.Current

I checked this method and visits history looks fine.

0

You first need to identify contact and then you can use Tracker.Current.Contact notation. You need to use code from this article https://doc.sitecore.net/sitecore%20experience%20platform/digital%20marketing/sitecore%20forms/setting%20up%20and%20configuring/walkthrough%20creating%20a%20custom%20submit%20action%20that%20updates%20contact%20details and it's execute method. We had no issues implementing similar code in our solution recently.

9
  • Hi Peter, this is exactly what I try to use, it's linked in my question. The problem is with Execute method, where Tracker.Current is null (not Tracker.Current.Contact) so the method throws exception. It works fine for me if I add to the code: Tracker.StartTracking(), before calling Tracker.Current.Contact.
    – whuu
    Commented May 10, 2018 at 6:24
  • 1
    Try also in your Execute method what are values for these parameters -> Tracker.IsActive and Sitecore.Context.Site.Tracking().EnabledTracking Commented May 10, 2018 at 6:35
  • 1
    That sounds like a bug. I would love a Sitecore Support ticket Commented May 10, 2018 at 18:55
  • 1
    Already contacted support, I will update the answer after I receive their feedback. For now the workaround is to turn off ajax form, or to call Tracker.StartTracking() inside action code.
    – whuu
    Commented May 10, 2018 at 19:31
  • 1
    Keeping fingers crossed :) Commented May 10, 2018 at 20:51

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.