7.1 Umbraco Forms integration
Theo Paraskevopoulos edited this page Oct 15, 2016
·
2 revisions
To create a Pipeline from Umbraco form, use the Pipeline Helper in a new workflow type. For more information on extending Umbraco forms see https://our.umbraco.org/documentation/Products/UmbracoForms/Developer/Extending/Adding-a-Workflowtype
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.Enums;
using Umbraco.Core.Logging;
using Umbraco.Forms.Data;
using Umbraco.Forms.Data.Storage;
using Umbraco.Forms.Core.Services;
using Umbraco.Forms.Web.Services;
using PipelineCRM.Helpers;
namespace PipelineDemo
{
public class CreateOpportunity : WorkflowType
{
// Generates the new workflow details for Contour in the workflow dropdown in Contour
public CreateOpportunity()
{
// Need to generate a new guid for the new custom workflow - add your own GUID
this.Id = new Guid("072950ed-274d-4f32-a258-5599e2ba4867");
this.Name = "New Pipeline opportunity";
this.Description = "Creates an opportunity in Pipeline";
}
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
Umbraco.Core.Logging.LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "the IP " + record.IP + " has submitted a record");
// Get product page
var helper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
var currentPage = helper.AssignedContentItem;
// Get form values
string name = record.RecordFields.SingleOrDefault(x => x.Value.Alias == "name").Value.ValuesAsString();
string organisation = record.RecordFields.SingleOrDefault(x => x.Value.Alias == "organisation").Value.ValuesAsString();
string email = record.RecordFields.SingleOrDefault(x => x.Value.Alias == "email").Value.ValuesAsString();
string telephone = record.RecordFields.SingleOrDefault(x => x.Value.Alias == "telephone").Value.ValuesAsString();
string comments = record.RecordFields.SingleOrDefault(x => x.Value.Alias == "comments").Value.ValuesAsString();
// Create opportunity using the Helper
var pipelineService = PipelineHelper.CreatePipeline(
"Enquiry about " + currentPage.Name,
name,
email,
telephone,
organisation,
comments
);
foreach (RecordField rf in record.RecordFields.Values)
{
// and we can then do something with the collection of values on each field
List<object> vals = rf.Values;
// or just get it as a string
rf.ValuesAsString();
}
return WorkflowExecutionStatus.Completed;
}
public override List<Exception> ValidateSettings()
{
List<Exception> exceptions = new List<Exception>();
return exceptions;
}
}
}