Copied to clipboard

Flag this post as spam?

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


  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 09:14
    Mikkel Olsen
    0

    Custom Workflow C# - Post form to URL

    Hello all,

    Im currently working on a post to form url workflow type in contour that needs to populate any given data from different fieldtypes. Textstring, textfield etc. It basically needs to support any kind og fieldtype to be dynamic.

    The data submitted in the contour form should be populated to an email based on a dropdownlist selection (zipcodes) thats pulling its data from a prevalue source. The email is unique to every zipcode and is located on the property of that node.

    I need to populate the data from the fieldtypes .- till now i have it working by requesting on the specific fieldtype alias, however this isnt dynamic at all, since the customer might add a new field with a different name in the future..

    I hope it made a bit sense :-)

    /Mikkel

  • Comment author was deleted

    Jun 19, 2013 @ 10:03

    Hey Mikkel,

    Have you checked out the sourcecode for the default providers? Maybe that has some snippets that can help you can find it here http://our.umbraco.org/FileDownload?id=5060

     

  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 10:19
    Mikkel Olsen
    0

    Thanks Tim,

    I will check it out asap :-)

    However I am a bit confused on where to put the class that contains the workflow and its methods in order to make my umbraco website / contour form execute that given class.

    /Mikkel

  • Comment author was deleted

    Jun 19, 2013 @ 10:20

    Just compile and drop the assembly in your bin, then you should be able to assign a new workflow of that type like this http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Editor/Attaching-Workflows/

  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 10:25
    Mikkel Olsen
    0

    Thanks Tim, 

    That was just what I was looking for! :-)

    Cheers,

    Mikkel

  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 10:48
    Mikkel Olsen
    0

    Sorry to interupt you once more, Tim.

    It doesn't seem that my custom workflow type is being loaded into the API? - I have followed your instructions (compile, copy/paste the assembly to the bin folder) however it doesn't show up in the dropdownlist along with the default ones?

    /Mikkel

  • Comment author was deleted

    Jun 19, 2013 @ 10:49

    Mind sharing the code?

  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 10:53
    Mikkel Olsen
    0

    namespace SomeProjectName.Library.Helpers

    {

        public class PostFormToUrlExtended : WorkflowType

        {

            [Umbraco.Forms.Core.Attributes.Setting("Url", description = "Enter the url to post to", control = "Umbraco.Forms.Core.FieldSetting.TextField")]

            public string Url { get; set; }

     

            [Umbraco.Forms.Core.Attributes.Setting("Method", description = "POST or GET", prevalues = "POST,GET,PUT,DELETE", control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist")]

            public string Method { get; set; }

     

            [Umbraco.Forms.Core.Attributes.Setting("Fields", description = "Map the needed fields", control = "Umbraco.Forms.Core.FieldSetting.FieldMapper")]

            public string Fields { get; set; }

     

            [Umbraco.Forms.Core.Attributes.Setting("User", description = "(optional)", control = "Umbraco.Forms.Core.FieldSetting.TextField")]

            public string Username { get; set; }

     

            [Umbraco.Forms.Core.Attributes.Setting("Password", description = "(optional)", control = "Umbraco.Forms.Core.FieldSetting.Password")]

            public string Password { get; set; }

     

            public PostFormToUrlExtended() {

                this.Id = new Guid("FD02C929-4E7D-4f90-B9FA-13D074A76688");

                this.Name = "Post form to url";

                this.Description = "Posts the form to a url, either as POST or GET";

            }

     

            public override List<Exception> ValidateSettings() {

                List<Exception> l = new List<Exception>();

     

                if (string.IsNullOrEmpty(Url))

                    l.Add(new Exception("'Url' setting has not been set"));

     

                return l;

            }

     

            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) {

     

                string[] _fields = Fields.Split(';');

     

                WebClient client = new WebClient();

                using (client) {

                    NameValueCollection values = new NameValueCollection();

     

                    if (_fields.Length > 0) {

                        foreach (string field in _fields) {

                            string[] vals = field.Split(',');

                            if (vals.Length == 3) {

     

                                string value = "";

                                string alias = vals[0];

     

                                if (!string.IsNullOrEmpty(vals[2]))

                                    value = vals[2];

                                else

                                {

     

                                    var rf = record.RecordFields[new Guid(vals[1])];

     

                                    value = rf.ValuesAsString();// string.Join(",", record.RecordFields[new Guid(vals[1])].Values.ConvertAll<string>(val => val.ToString()).ToArray());

                                }

     

                                values.Add(alias, value);

                            }

                        }

                        /*

                        if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(UserName))

                            client.Credentials = new NetworkCredential(UserName, Password);

                        */

     

     

                    } else {

                        foreach (RecordField rf in record.RecordFields.Values) {

                            values.Add(rf.Field.Caption.Replace(" ", ""), rf.ValuesAsString());

                        }

                    }

     

     

                    client.UploadValues(Url, Method, values);

                }

     

               return WorkflowExecutionStatus.Completed;

            }

     

        }

    }

    that is the workflow type, and it is located inside my class library which is being compiled and updated everytime I build ..

     

    /Mikkel

  • Comment author was deleted

    Jun 19, 2013 @ 10:55

    Think you'll need a new id since it's copied from the original workflow type

     this.Id = new Guid("FD02C929-4E7D-4f90-B9FA-13D074A76688");

    So make sure the change to guid to something else then it should show up

  • Mikkel Olsen 20 posts 94 karma points
    Jun 19, 2013 @ 10:59
    Mikkel Olsen
    0

    Well that sure did the trick! I was kinda sure that it was something that obvious lol.. Anyways, thanks again for the help, Tim! :-)

    /MIkkel

  • Comment author was deleted

    Jun 19, 2013 @ 11:00

    Sweet glad it's working :)

Please Sign in or register to post replies

Write your reply to:

Draft