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"); }
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.
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.
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.
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();
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?
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 :)
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.
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;
}
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.
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.
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:
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!
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.
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
I've filed it as a bug:
http://issues.umbraco.org/issue/CON-593
So please vote on it.
Thanks Martin, I've just voted on it. Glad we're not the only ones experiencing this issue, just hope it gets sorted soon,
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:
Add the following class in separate project or app_code folder:
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:
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?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 :)
sorry, typo:
...for a specific Workflow, on whatever form you add the workflow.
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.
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 :)
Tim fixed it!
It's coming out in version 3.0.22.
http://issues.umbraco.org/issue/CON-593
Comment author was deleted
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
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?
Comment author was deleted
Can't you just use the default value option? You can set that in the UI for each field...
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
Yeah on opened there isn't a record yet... so think that workaround is the best bet
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.
is working on a reply...