Copied to clipboard

Flag this post as spam?

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


  • Tam Q 2 posts 23 karma points
    May 20, 2014 @ 07:22
    Tam Q
    1

    Opened Event of Simple Custom Workflow Is Not Working

    I created a simple custom workflow and added it to the Opened event of a Contour form.  The Execute method doesn't get called when opening the form up or on refresh.  The weird thing is that the Execute method does get called (multiple times) when I hit the submit button of the Contour form.

    Could someone please let me know if I doing something wrong or if this is a bug? 

    Here's the code:

    namespace Mkt.Core.umbraco.WorkflowTypes
    {
        public class MktWorkflow : WorkflowType
        {
            [Umbraco.Forms.Core.Attributes.Setting("Field",
                description = "The field named for test",
                control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string FieldName { get; set; }

            public MktWorkflow()
            {
                this.Id = new Guid("31804252-AD24-4755-B040-2DE0282D893D");
                this.Name = "Prepopulate Contour Form";
                this.Description = "Prepopulate Contour Form";
            }

            public override List ValidateSettings()
            {
                List exceptions = new List();
                return new List();
            }
            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                // LINQ statement that returns the field based on the field name
                RecordField field = record.RecordFields.Values.Where(value => value.Field.Caption == FieldName).FirstOrDefault();

                if (field != null)
                {
                    field.Values.Clear();
                    field.Values.Add("test");
                }

                return WorkflowExecutionStatus.Completed;
            }
        }
    }
  • Tam Q 2 posts 23 karma points
    May 21, 2014 @ 04:16
    Tam Q
    0

    Could someone please tell me if there's a solution to this issue?  I have an urgent need for this as I will need to prepopulate the contour form fields from different datasources such as cookie, DB, session, etc.

    Thanks in advance for your help!

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 05, 2014 @ 15:36
    Martin Lingstuyl
    0

    Hi Tam Q,

    Do you have a solution on this problem by now?

    I'm experiencing the same problems here. (contour 3.0.17, umbraco 6.2.x) We only had the problem when using the Razor version of the Form. The usercontrol version does execute the Opened state. So maybe for you switching to usercontrol form might be the solution.

     

  • Robby Cowell 20 posts 103 karma points
    Sep 11, 2014 @ 15:22
    Robby Cowell
    1

    I'm also interested in a solution to this as we're experiencing the same issue.

    I've attached a custom workflow for 'When the form has been opened'. However when opening the page the form renders on, the workflow is not triggered.

    Another point to mention is that this workflow IS hit when I submit a completed form. So it seems that the 'When the form has been opened' and the 'When the form has been submitted' stages are doing the same thing, which suggests there is some kind of bug in the code.

    I posted my own topic on this issue here

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 12, 2014 @ 10:35
    Martin Lingstuyl
    0

    I've filed it as a bug:

    http://issues.umbraco.org/issue/CON-593

    So please vote on it.

  • Robby Cowell 20 posts 103 karma points
    Sep 12, 2014 @ 11:55
    Robby Cowell
    0

    Thanks Martin, I've just voted on it. Glad we're not the only ones experiencing this issue, just hope it gets sorted soon,

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 12, 2014 @ 12:11
    Martin Lingstuyl
    0

    Me too,

    in the meantime: I've created some code that triggers the logic anyway. I had a custom workflow on the Opened Event, so to circumvent the problem I added the custom code to another class that I call from the Form.cshtml view. It's not entirely neat, it just triggers one specific workflow, but for me it was okay and you might be interested.

     

    In /umbraco/plugins/umbracocontour/views/forms.cshtml add the following workaround line:

    @if (Model.SubmitHandled)
    {
        <p class="contourMessageOnSubmit">@Html.Raw(Model.MessageOnSubmit)</p>
    }
    else
    {
    //Workaround for Opened State
    CustomClasses.Triggers.WorkflowTrigger.Execute(Model.FormId);

    .... etc   

    Add the following class in separate project or app_code folder:

    namespace CustomClasses.Triggers
    {
        public class WorkflowTrigger
        {
            public static void Execute(Guid FormId)
            {           
                using (RecordStorage store = new RecordStorage())
                {
                    using (FormStorage forms = new FormStorage())
                    {
                        Form SelectedForm = forms.GetForm(FormId);
                        using (WorkflowStorage wfs = new WorkflowStorage())
                        {
                            List<Workflow> wflist = wfs.GetAllWorkFlows(SelectedForm);
                            Guid wfGuid = new Guid("<YOUR WORKFLOW GUID HERE>");

    //Check if the workflow is added to the form
                            Workflow wf = wflist.Where(it => it.Type.Id == wfGuid).FirstOrDefault();

                            if (wf != null)
                            {
                                //Do something

                            }
                            else
                                //workflow not found

                        }
                    }
                }
            }
        }
    }
  • Robby Cowell 20 posts 103 karma points
    Sep 15, 2014 @ 16:24
    Robby Cowell
    0

    Great thanks, very nice workaround Martin. I'm pulling in the correct form through Form.cshtml. I did make a small change to my Linq statement:

    Workflow wf = wflist.Where(it => it.Id == wfGuid).FirstOrDefault();

    A quick question though, what kind of logic would you put within your example's if statement, checking if wf is null:

    if (wf != null)
    {
        //Do something
    }
    

    I'm guessing it's something like wf.ExectuesOn(); but I'm really not sure, what would I put in here if I simply wanted the selected workflow to validate and run?

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 15, 2014 @ 16:56
    Martin Lingstuyl
    0

    Are you sure the it.id == wfGuid works? Maybe you're specifically selecting the workflow connected to the form then? In my case I'm pulling the TypeId, which is the same for a specific Form, on whatever form you add the workflow.

    About the //Do something code:

    I actually didnt discover how to manually trigger a workflow, so I just added code that does the same as the workflow code.

    (which is why it's not a very neat solution, but for us it works)

    If you discover how to manually trigger a workflow through C#, please let me know, I'd be very interested :)

     

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 16, 2014 @ 08:25
    Martin Lingstuyl
    0

    sorry, typo:

    ...for a specific Workflow, on whatever form you add the workflow.

  • Robby Cowell 20 posts 103 karma points
    Sep 22, 2014 @ 18:08
    Robby Cowell
    0

    Hi Martin, you were right, I was specifically selecting the workflow. Thanks for your answer, I spent quite a while trying to find how to execute the workflow code, but unfortunately had no luck; looks like I'll take your approach and add the code in again in the new workflow classes. I'll continue to have a play around with it, and if I get anywhere, I'll post the results.

    The Umbraco developers working on Contour seem to have been quiet on the forum recently, and this workflow bug is causing us a lot of problems, this should really be fixed, especially as it seems to be just a case of the workflow events not being wired up correctly. This is a major problem in my opinion and I'm disappointed we haven't heard anything regarding the issue yet.

  • Martin Lingstuyl 202 posts 379 karma points
    Sep 25, 2014 @ 08:18
    Martin Lingstuyl
    0

    I agree, with us it also caused a major issue and it didn't communicate well towards my client.

    Anyway, it seems that the only thing we can do is wait. (or pay 3000 dollars and get a full service account :)

  • Martin Lingstuyl 202 posts 379 karma points
    Oct 28, 2014 @ 12:16
    Martin Lingstuyl
    0

    Tim fixed it!

    It's coming out in version 3.0.22.

    http://issues.umbraco.org/issue/CON-593

  • Comment author was deleted

    Nov 03, 2014 @ 09:55

    And 3.0.22 is out, would be ace if you guys can confirm that the bug is fixed

    you can find it on the project page http://our.umbraco.org/projects/umbraco-pro/contour

    upgrade instructions can be found here http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Installation/Upgrade

  • marcelh 171 posts 471 karma points
    Nov 21, 2014 @ 07:35
    marcelh
    0

    Hi Tim, I can confirm that the Opened event gets hit now, thanks. However, I have the same scenario as the OP here, where fields need to be prepopulated based on custom logic.

    Using the code below, the record.RecordFields.Values always count 0. Seems that the records holds no values for the fields in the form. In other words, the field below is never found. Where would I go if I wanted to preselect an item in a dropdownlist? Or set a value in a textbox?

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                // LINQ statement that returns the field based on the field name
                RecordField field = record.RecordFields.Values.Where(value => value.Field.Caption == FieldName).FirstOrDefault();
    
                if (field != null)
                {
                    field.Values.Clear();
                    field.Values.Add("test");
                }
    
                return WorkflowExecutionStatus.Completed;
            }
    
  • Comment author was deleted

    Nov 21, 2014 @ 10:21

    Can't you just use the default value option? You can set that in the UI for each field... 

  • marcelh 171 posts 471 karma points
    Nov 21, 2014 @ 13:50
    marcelh
    0

    No, that's not an option. The form needs to be prefilled with some variables on the page and context, which sometimes needs some additional logic to be executed.

    Since the Opened event is there, it would make sense to set those default values on that event. It keeps the code clear, consise and maintanable. But without recordfields available there is not much to do ;-)

    The workaround I used now is to first insert those variables into the session and in display them in the form.

  • Comment author was deleted

    Nov 21, 2014 @ 13:51

    Yeah on opened there isn't a record yet... so think that workaround is the best bet

  • marcelh 171 posts 471 karma points
    Nov 21, 2014 @ 13:54
    marcelh
    0

    It works, but it's my favorite piece of code.

    I understand that in the lifecycle there is record yet. Would be nice though if you were able to influence the values of record or form somehow. Otherwise having the record or the form in the Opened event doesn't add much value.

Please Sign in or register to post replies

Write your reply to:

Draft