Trying to programmatically update form field value in a custom workflow
Hi,
I've been banging my head against this all day and am now just at a loss. I have built a custom workflow and applied it to one of my forms. If I debug and step through the process I can see that my code is adding the appropriate value to the record object. However, when I view the form records in the Dashboard I don't see the text I am trying to insert.
I'm running Umbraco 4.7.0 and Contour 1.1.11 and IIS is configured to us .Net Framework 4 for the site.
My code is as follows:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Umbraco.Forms.Core; using Umbraco.Forms.Core.Services; using Umbraco.Forms.Data.Storage; namespace AM.Umbraco.NRAILA.workflows { public class UpdateEvcEmail : WorkflowType { public UpdateEvcEmail() { this.Name = "Update EVC Email Address"; this.Id = new Guid("c90e577e-b373-4be1-8024-02d6210b83fe"); this.Description = "Inserts an EVC's contact email address into the record using a supplied EVC ID."; } public override List<Exception> ValidateSettings() { List<Exception> exceptions = new List<Exception>(); return exceptions; } public override global::Umbraco.Forms.Core.Enums.WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) { var recip = record.GetRecordField(new Guid("d25b8778-c95d-42fd-b97e-6948c8176d01")); recip.Values.Clear(); recip.Values.Add("this is a test"); FormStorage fs = new FormStorage(); Form f = fs.GetForm(record.Form); RecordStorage rs = new RecordStorage(); rs.UpdateRecord(record, f); rs.UpdateRecordXml(record, f); fs.Dispose(); rs.Dispose(); return global::Umbraco.Forms.Core.Enums.WorkflowExecutionStatus.Completed; } } }
And yes, I have double and triple-checked that the guid I'm using for my form field is the correct one. If I use the guid for a different field I can read in the text entered during the form submission.
No exceptions are thrown. It's as-if UpdateRecord() and UpdateRecordXml() have no effect at all.
If you want to change the value you'll have to attach the workflow to the approved state doing it on the submitted state it will get overwritten by the entered values
I decided to go another route though. Instead of updating a field in the record (so that a different workflow could use the value to send an email) I am not compiling and sending the email in my own custom control and it works quite well.
But I woudn't be surprised to find myself in the future needing to update a record field and so I'll remember this tip.
Trying to programmatically update form field value in a custom workflow
Hi,
I've been banging my head against this all day and am now just at a loss. I have built a custom workflow and applied it to one of my forms. If I debug and step through the process I can see that my code is adding the appropriate value to the record object. However, when I view the form records in the Dashboard I don't see the text I am trying to insert.
I'm running Umbraco 4.7.0 and Contour 1.1.11 and IIS is configured to us .Net Framework 4 for the site.
My code is as follows:
And yes, I have double and triple-checked that the guid I'm using for my form field is the correct one. If I use the guid for a different field I can read in the text entered during the form submission.
No exceptions are thrown. It's as-if UpdateRecord() and UpdateRecordXml() have no effect at all.
What am I missing?
Thanks!
Comment author was deleted
Hi Chester
If you want to change the value you'll have to attach the workflow to the approved state doing it on the submitted state it will get overwritten by the entered values
Thanks Tim! That makes perfect sense.
I decided to go another route though. Instead of updating a field in the record (so that a different workflow could use the value to send an email) I am not compiling and sending the email in my own custom control and it works quite well.
But I woudn't be surprised to find myself in the future needing to update a record field and so I'll remember this tip.
Cheers,
c
is working on a reply...