Copied to clipboard

Flag this post as spam?

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


  • Balram Narad 37 posts 89 karma points
    Nov 09, 2017 @ 11:42
    Balram Narad
    0

    Custom Workflows not showing up in dropdown list

    I am trying to create a custom workflow type but it is not showing on the dropdown list within the contour form. I have one custom workflow type that is working but not this second one. I have tried using the first one and changing the guid name and description but that doesn't show up either.

    Code is shown below any help suggestions welcome

    namespace Wyre.Umbraco.Models{
    public class MissedBinEmailWorkflow : WorkflowType
    {
    
        public MissedBinEmailWorkflow()
        {
            this.Id = new Guid("2grhtr45-9154-6dau-ed54-gh21aed6g7h3");
            this.Name = "A Missed Bin Email";
            this.Description = "Send Email to Cutomer ";
        }
    
    
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
    
            foreach (var field in record.RecordFields.Values)
            {
                var fieldItem = field.Values;
                var fieldName = field.Field.Caption;
                if (fieldName == "Is there a yellow or red tag on your bin")
                {
                    List<object> fieldValue = fieldItem;
                    foreach (string fv in fieldValue)
                        if (fv == "Yes")
                        {
                            HttpContext.Current.Response.Redirect("https://www.google.com");
                        }
                }
            }
    
            return WorkflowExecutionStatus.Completed;
    
        }
    
    
        public override List<Exception> ValidateSettings()
        {
            return new List<Exception>();
        }
    
    }}
    

    Thanks Bal

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 10, 2017 @ 22:56
    Ben Palmer
    100

    Hi Bal,

    I ran this on a fresh Umbraco installation and immediately ran into the following error:

    Unable to load form: The type initializer for 'Nested' threw an exception.
    

    So, I played around and looks like there's something wrong with your GUID. I swapped this out for a newly generated GUID and it seems to work just fine (error is no longer displaying, but I haven't tested the whole form workflow, I'll leave that to you).

    Here's a tweaked version of your code:

    using System;
    using System.Collections.Generic;
    using System.Web;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Enums;
    
    namespace UmbracoSandbox.WorkflowTypes
    {
        public class MissedBinEmailWorkflow : WorkflowType
        {
            public MissedBinEmailWorkflow()
            {
                Id = new Guid("7793f98d-266f-4905-b2f2-9d27438da763");
                Name = "A Missed Bin Email";
                Description = "Send Email to Cutomer ";
            }
    
            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                foreach (var field in record.RecordFields.Values)
                {
                    List<object> fieldItem = field.Values;
                    string fieldName = field.Field.Caption;
    
                    if (fieldName == "Is there a yellow or red tag on your bin")
                    {
                        List<object> fieldValue = fieldItem;
    
                        foreach (string fv in fieldValue)
                        {
                            if (fv == "Yes")
                            {
                                HttpContext.Current.Response.Redirect("https://www.google.com");
                            }
                        }
                    }
                }
    
                return WorkflowExecutionStatus.Completed;
            }
    
            public override List<Exception> ValidateSettings()
            {
                return new List<Exception>();
            }
        }
    }
    

    Hope that helps!

  • Balram Narad 37 posts 89 karma points
    Nov 13, 2017 @ 15:35
    Balram Narad
    0

    Thanks Ben that's worked a treat

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Nov 13, 2017 @ 15:45
    Nik
    2

    Hi Balram,

    Great news that Ben's answer got it working for you. I would be great if you could flag that as the solution for other :-)

    Just for some future reference, looking at your original post your guid is invalid because of the characters it contains. A Guid must be in a particular format and can only contain numbers and letters upto the letter F as each character is a hex character.

    For more information this link might be quite helpful :-) https://betterexplained.com/articles/the-quick-guide-to-guids/

    Thanks,

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft