Copied to clipboard

Flag this post as spam?

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


  • Luke Phelan 14 posts 85 karma points c-trib
    Sep 05, 2017 @ 07:41
    Luke Phelan
    0

    Null reference error when submitting form with custom workflow.

    Hi,

    I am making a custom workflow for a client website using Umbraco Forms 6.0.1 and created a new workflow type following the documentation here:

    https://our.umbraco.org/documentation/Add-ons/umbracoforms/developer/Extending/Adding-a-Type

    I am able to create and save the Workflow without any issues, but when I go to submit the form I recieve the following null reference error:

    Null Reference Stack Trace

    My Workflow class looks like this:

        public class SalesforceWorkflow : WorkflowType
    {
        public SalesforceWorkflow()
        {
            this.Name = "Salesforce Integration";
            this.Id = new Guid();
            this.Description = "This will save a record in Salesforce based on the supplied Lead Id and Form Fields.";
            this.Icon = "icon-coins";
        }
    
        [Setting("Lead Id",
            description = "The Id of the lead in salesforce.",
            view = "TextField")]
        public string LeadId { get; set; }
    
        [Setting("Field Mapping", description = "Use this field to pair the SalesForce Fields to the form fields", view = "FieldMapper")]
        public object FieldMappings { get; set; }
    
    
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            LogHelper.Info<SalesforceWorkflow>("New form submission from " + record.IP);
            foreach (RecordField rf in record.RecordFields.Values)
            {
                //and we can then do something with the collection of values on each field
                List<object> vals = rf.Values;
    
                //or just get it as a string
                rf.ValuesAsString();
            }
    
            //If we altered a field, we can save it using the record storage
            RecordStorage store = new RecordStorage();
            store.UpdateRecord(record, e.Form);
            store.Dispose();
    
            //we then invoke the recordservice which handles all record states //and make the service delete the record.
            RecordService rs = new RecordService();
            rs.Delete(record, e.Form);
    
            return WorkflowExecutionStatus.Completed;
        }
    
        public override List<Exception> ValidateSettings()
        {
            var exceptions = new List<Exception>();
    
    
            if(string.IsNullOrEmpty(this.LeadId))
                exceptions.Add(new Exception("Please specify a Lead Id."));
            return exceptions;
        }
    
    }
    

    Is there another step that I am missing? The client has yet to purchase the forms license so it is still in trial mode. Does that make a difference?

    Thanks!

  • Luke Phelan 14 posts 85 karma points c-trib
    Sep 05, 2017 @ 23:19
    Luke Phelan
    0

    I see what I've done wrong. I was creating a new empty Guid for each instance, instead of specifying one, which was causing the exception when the WorkflowService was trying to find the workflow.

Please Sign in or register to post replies

Write your reply to:

Draft