Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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

  • Paul Marden 221 posts 298 karma points
    Nov 29, 2011 @ 16:40
    Paul Marden

    Retrieving form values in a workflow

    Quick question.... is the only way to access a contour form value in a workflow to use the [# ] notation and retrieve a request collection value?

  • Seth Niemuth 275 posts 396 karma points
    Nov 29, 2011 @ 18:24
    Seth Niemuth

    Here is an example of a send to an email that is entered by the user in the form workflow:

    The email service is just a method in our repository which sends off an email using the Xslt file specified in the properties but this shows being able to get the value of a field out in a workflow in XML format. 

     using System;
    using System.Collections.Generic;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Data.Storage;
    using System.Xml;
    using Umbraco.Forms.Core.Attributes;
    using System.Web;
    using QHotels.Services;
    using System.Text.RegularExpressions;
    using System.IO;
     public class SendEmailToUser : WorkflowType
            // Generates the new workflow details for Contour in the workflow dropdown in Contour
            public SendEmailToUser()
                // Need to generate a new guid for the new custom workflow - add your own GUID
                this.Id = new Guid("6E638E92-0F61-493c-A1AE-DED9D3F3333A");
                this.Name = "Send User Email";
                this.Description = "If you want to send an email to a field entered in the form";


            [Setting("Email Look Up Field", description = "Enter the receiver email lookup field", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string EmailLookUpField { get; set; }


            [Setting("Xslt File", description = "The name of the file within the XSLT folder that will be the email template", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string XsltFile { get; set; }


            [Setting("Email Subject", description = "Subject of the email", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string EmailSubject { get; set; }


            private const string LookUpFieldXpath = "//fields/child::* [caption =  \"{0}\"]";


            public override List<Exception> ValidateSettings()
                List<Exception> exceptions = new List<Exception>();
                if (string.IsNullOrEmpty(EmailLookUpField))
                    exceptions.Add(new Exception("'Email Look up field' setting not filled out"));


                if (string.IsNullOrEmpty(EmailSubject))
                    exceptions.Add(new Exception("'Email subject field' setting not filled out"));


                if (string.IsNullOrEmpty(XsltFile))
                    exceptions.Add(new Exception("'Xslt File' setting not filled out"));


                        string mappedXsltPath = HttpContext.Current.Server.MapPath("/xslt" + XsltFile);
                        if (!File.Exists(mappedXsltPath))
                                new Exception("'Xslt File' is not a valid file within the xslt folder of the website"));


                    catch (Exception)
                        exceptions.Add(new Exception("'Xslt File' is not a valid file within the xslt folder of the website"));




                return exceptions;


            public override Umbraco.Forms.Core.Enums.WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
                IEmailServices emailServices = IoCWrapper.Resolve<IEmailServices>();
                    RecordsViewer viewer = new RecordsViewer();
                    XmlNode xml = viewer.GetSingleXmlRecord(record, new XmlDocument());


                    string email = GetEmailAddressViaLookUp(xml);
                    string mappedXsltPath = HttpContext.Current.Server.MapPath("/xslt/" + XsltFile);


                    if (!string.IsNullOrEmpty(email) && Regex.IsMatch(email, Resources.Regex.Email))
                        emailServices.SendContourEmail(email, EmailSubject, xml, mappedXsltPath);


                catch (Exception ex)


                return WorkflowExecutionStatus.Completed;


            private string GetEmailAddressViaLookUp(XmlNode xml)
                // EmailLookUpField - this is the field which we have specified in the workflow that has the email address 
                // values assigned to them, in our case the "Sectors" checkbox list.
                string xpath = string.Format(LookUpFieldXpath, EmailLookUpField);


                XmlNode destinationEmailNode = xml.SelectSingleNode(xpath);


                if (destinationEmailNode != null)
                    XmlNodeList destinationNodes = destinationEmailNode.SelectNodes("values/value");
                    if (destinationNodes != null)
                        foreach (XmlNode destinationNode in destinationNodes)
                            if (destinationNode.Attributes != null)
                                return destinationNode.InnerText;


                return string.Empty;
  • Tom Smith 98 posts 172 karma points
    Nov 29, 2011 @ 18:32
    Tom Smith

    Hi Paul,

    I use a quick (and dirty) helper method to grab content of a form field by field caption

    public static RecordField GetByLabel(this Record record, string labelName)


    return record.RecordFields.Values.Where(value => value.Field.Caption == labelName).FirstOrDefault();


    You already have the record from the public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)

    Can use the ValuesAsString() method on the returned record field to get a string value e.g.

    string recipient = CogFormHelpers.GetByLabel(record, EmailFieldLabel).ValuesAsString(); 

    where EmailFieldLabel is the caption of the email field e.g. "Email Address"

    Many Thanks,





Please Sign in or register to post replies

Write your reply to: