Copied to clipboard

Flag this post as spam?

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

  • Gabor Ferencz 15 posts 105 karma points
    29 days ago
    Gabor Ferencz

    Umbraco Forms throws NullReference Error when including email workflow step

    I have an issue where I have a form that I'm trying to submit using the RecordService:

     var form = _formStorage.GetForm(dto.FormId);
                var fieldDic = RecordFields(form, dto, siteSettings);
                var record = new Record()
                    Created = DateTime.Now,
                    Form = form.Id,
                    RecordFields = fieldDic,
                    State = FormState.Submitted
                record.RecordData = record.GenerateRecordDataAsJson();
                _recordStorage.Submit(record, form); 

    This throws an invalidOperationException at the Submit method:

    at Umbraco.Forms.Core.Services.PageService.GetPageElements() at Umbraco.Forms.Core.Services.WorkflowService.ExecuteWorkflows(List`1 workflows, RecordEventArgs e) at Umbraco.Forms.Core.Services.WorkflowService.ExecuteWorkflows(Record record, Form form, FormState state, Boolean editMode) at Umbraco.Forms.Core.Services.RecordService.Submit(Record record, Form form) at RedCarnation.Umbraco.Services.FormSubmitService.SubmitNewsletterForm(NewsletterFormSubmitModel dto) in D:\Client\RedcarnationHotels\RedCarnation.Umbraco\Services\FormSubmitService.cs:line 65

    I'm at a loss as to why this errors. The form is being rendered custom, but the data submits. The email step is bog standard, and I have tested my SMTP server details are correct. Any help would be appreciated!

  • Marc Goodson 1281 posts 8670 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson

    Hi Gabor

    I'm not sure how to resolve your issue, but I think it may be failing because an Umbraco workflow step can be modified to use 'magic strings' to reference values from the current page to utilise in the Workflow step configuration.

    For example, you could have a workflow step that sends an email when the form is filled in, but you might set the 'From' email address from the document type of the page that the form is included on... eg for a different department, you can have one form but allow editors to customise the workflow behaviour by settings on the particular page.

    To do this, the workflow steps need to get all the details of the current page -- just in case you might be doing this... and there is a method that builds a hashset of these values, so the magicstring lookups can work called GetPageElements().

    public Hashtable GetPageElements()
            var pageId = _contextAccessor.UmbracoContext.PublishedRequest.PublishedContent.Id;
            return GetPageElements(pageId);          

    You can see this relies on there being an underlying PublishedRequest when the workflow steps are run...

    ... but in your stack trace this is where the error is being thrown, so is it possible with your custom rendering that somehow there isn't an underlying PublishedRequest when you call the recordservice save?

    ... but if that is the case, and the cause of the problem I'm not sure how to resolve :-( - which version of Umbraco Forms are you using?

    if you are on the latest version, it might be worth raising this via the issue tracker:



  • Gabor Ferencz 15 posts 105 karma points
    7 days ago
    Gabor Ferencz

    Thanks Marc,

    I think the issue might be to do with the fact that the forms have moved to the database, but my implementation didn't migrate them yet. The API was working against the DB code...

    Hopefully migrating them into the DB will fix it. Thanks for your response! Gabor

  • Marc Goodson 1281 posts 8670 karma points MVP 5x c-trib
    7 days ago
    Marc Goodson

    Aha, will watch out for that! glad you got it working!

Please Sign in or register to post replies

Write your reply to: