Copied to clipboard

Flag this post as spam?

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


  • Maxi 13 posts 152 karma points
    Jun 02, 2015 @ 10:47
    Maxi
    0

    Converting just a workflow from Contour to Umbraco Forms

    HI,

    I have two websites, one using contour and one using umbraco forms.I created a Workflow for the contour website with no problems. However, I can't find any documentation on updating worflows from contour to forms. I did find the migration package but since I don't want to migrate the contour site I just want to use my custom workflow from this site on another.

    Any help much appreciated.

    Thanks

    Maxi

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 02, 2015 @ 10:53
    Dennis Aaen
    0

    Hi Maxi,

    Perhaps this documentation about extending the workflows in Umbraco Forms with a workflow type can help you https://our.umbraco.org/documentation/Products/UmbracoForms/Developer/Extending/Adding-a-Workflowtype

    Hope this helps,

    /Dennis

  • Maxi 13 posts 152 karma points
    Jun 02, 2015 @ 11:16
    Maxi
    0

    Hi Dennis,

    My code follows the same standards, I then build my seperate project and copy the dll to the bin folder for my website. This works on the contour site with no problems but the umbraco forms website the workflow just doesn't appear. I have put my code below if this helps.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Forms.Data.Storage;
    using Umbraco.Forms.Core.Services;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Core.Attributes;
    using System.Xml;
    using System.Xml.XPath;
    using umbraco.BusinessLogic;

    namespace Contour.Addons.MulitpleEmails
    {
    public class MultipleEmails : Umbraco.Forms.Core.WorkflowType
    {
    [Umbraco.Forms.Core.Attributes.Setting("MultipleEmails mapping"description = "Setup Emails per selection <br /> (please us ^ to seperate email address)", control = "Contour.Addons.MulitpleEmails.EmailMapper", assembly = "Contour.Addons.MulitpleEmails")]
    public string scoremappings { get; set; }

    [Setting("Message", description = "Enter the intro message", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
    public string Message { get; set; }

    [Setting("EmailFrom", description = "Email from field alias that contains email address", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
    public string EmailFrom { get; set; }


    public MultipleEmails()
    {
    this.Name = "Emails per selection";
    this.Id = new Guid("F2V7D107-TY23-99RQ-P843-66M287X63789");
    this.Description = "Sends Email per pre-value selection";
    }

    public override List<Exception> ValidateSettings()
    {
    List<Exception> exceptions = new List<Exception>();
    return exceptions;
    }


    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
    {
    try
    {
    //calc score
    String Email = "";
    String subject = "Form has been completed";

    Dictionary<String, String> Emails = new Dictionary<String, String>();

    foreach (string mapping in scoremappings.Split(';'))
    {
    if (!string.IsNullOrEmpty(mapping) && mapping.Split(',').Length > 0)
    {
    Emails.Add(mapping.Split(',')[0], mapping.Split(',')[1]);
    }
    }

    foreach (RecordField rf in record.RecordFields.Values.Where(x => x.Field.FieldType.SupportsPrevalues && x.Field.PreValueSource.Type.GetPreValues(x.Field).Count > 0))
    {

    foreach (PreValue pv in rf.Field.PreValueSource.Type.GetPreValues(rf.Field).Where(x => x.Value.ToString() == rf.Values[0].ToString()))
    {
    Email += Emails[pv.Id.ToString()];
    subject = "Form completed for " + rf.Values[0].ToString();
    }
    }

    //set Email field
    //foreach (RecordField rf in record.RecordFields.Values)
    //{
    // if (rf.Field.Id == new Guid(field))
    // {
    // rf.Values.Clear();
    // rf.Values.Add(Email);
    // break;
    // }
    //}

    RecordsViewer viewer = new RecordsViewer();
    XmlNode xml = viewer.GetSingleXmlRecord(record, new XmlDocument());

    XPathNavigator navigator = xml.CreateNavigator();
    XPathExpression selectExpression = navigator.Compile("//fields/child::*");
    selectExpression.AddSort("@pageindex", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
    selectExpression.AddSort("@fieldsetindex", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
    selectExpression.AddSort("@sortorder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);

    XPathNodeIterator nodeIterator = navigator.Select(selectExpression);

    string list = "<dl>";

    while (nodeIterator.MoveNext())
    {
    list += "<dt><strong>" + nodeIterator.Current.SelectSingleNode("caption").Value + ": </strong><dt><dd>";
    XPathNodeIterator values = nodeIterator.Current.Select(".//value");
    while (values.MoveNext())
    list += values.Current.Value.Trim() + "<br/>";
    list += "</dd>";
    }

    list += "</dl>";

    string body = "<p>" + Message + "</p>" + list;

    SendMail(Email, subject, body);

    }
    catch (Exception ex)
    {
    LogError(ex.ToString());
    }



    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 WorkflowExecutionStatus.Completed;

    }

    private void LogError(string ErrorMessage)
    {
    String ErrorEmailAddress = "[email protected]";
    Log.Add(LogTypes.Error, 0, ErrorMessage);
    if (ErrorEmailAddress != string.Empty)
    {
    SendMail(ErrorEmailAddress, "Contour custom workflow dmc lookup error", ErrorMessage);
    }
    }


    private void SendMail(string to, string subject, string message)
    {
    try
    {
    var m = new System.Net.Mail.MailMessage
    {
    From = new System.Net.Mail.MailAddress(EmailFrom),
    Subject = subject,
    IsBodyHtml = true
    };

    foreach (var email in to.Split('^'))
    {
    m.To.Add(email);
    }
    m.Body = message;
    var s = new System.Net.Mail.SmtpClient("localhost");
    s.Send(m);
    }
    catch (Exception ex)
    {
    LogError(ex.Message);
    }
    }
    }
    }

    Thanks

    Maxi

  • Comment author was deleted

    Jun 04, 2015 @ 10:20

    Hey Maxi,

    You'll need to update the settings attributes, since those aren't webcontrols anymore but are angularjs views so they will look like this now

     [Attributes.Setting("Dirty Words", description ="Comma seperated list of forbidden words", view ="TextField")]

    public string DirtyWords { get; set; }

     

    [Attributes.Setting("Action", prevalues ="Delete Record,Approve Record", description ="What to do if it matches", view ="Dropdownlist")]

    public string Action { get; set; }

    It fetches them from the App_Plugins/UmbracoForms/Backoffice/Common/SettingTypes/ directory

    There you'll find all the default ones and those should get you started when you want to create a custom one

Please Sign in or register to post replies

Write your reply to:

Draft