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 36 posts 167 karma points
    Sep 22, 2020 @ 12:41
    Gabor Ferencz
    0

    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 2141 posts 14344 karma points MVP 8x c-trib
    Oct 13, 2020 @ 19:33
    Marc Goodson
    0

    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.

    https://our.umbraco.com/documentation/add-ons/umbracoforms/developer/Magic-Strings/

    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: https://github.com/umbraco/Umbraco.Forms.Issues/issues

    regards

    Marc

  • Gabor Ferencz 36 posts 167 karma points
    Oct 14, 2020 @ 15:39
    Gabor Ferencz
    100

    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 2141 posts 14344 karma points MVP 8x c-trib
    Oct 14, 2020 @ 17:28
    Marc Goodson
    0

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

Please Sign in or register to post replies

Write your reply to:

Draft