Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 281 posts 605 karma points c-trib
    Dec 04, 2013 @ 23:27
    ianhoughton
    0

    Custom workflow not saving dropdown value

    I have a Contour form with a custom workflow that creates a new job node on submission.

    The form has a number of dropdown lists, the values of which get saved to the [UFRecordsXml] table OK.

    When I check the unpublished node in the tree, all of the dropdown values are missing, and the data is missing from the [cmsPreviewXml] table.

    This is the workflow code that creates the new node:

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                Dictionary<string, string> mappings = new Dictionary<string, string>();
                int dtId = 0;
                int root = -1;
    
                int.TryParse(RootNode, out root);
                if (root == 0)
                    root = -1;
    
                string nameMapping = "NodeName";
    
                string[] array = Fields.Trim().Split('|');
    
                foreach (string s in array)
                {
                    string[] a = s.Trim().Split(',');
    
                    if (a.Count() == 1 && s.Trim().Length >= 4)
                    {
    
                        if (dtId == 0)
                            int.TryParse(s.Trim(), out dtId);
    
                    }
                    else if (a.Count() == 3)
                    {
    
                        string mapping = "";
    
                        if (!string.IsNullOrEmpty(a[2]))
                            mapping = record.RecordFields[new Guid(a[2])].ValuesAsString();
                        else if (!string.IsNullOrEmpty(a[1]))
                            mapping = Umbraco.Forms.Core.Services.WorkflowService.parseAttribute(e.Context, record, a[1]);
    
                        if ((!string.IsNullOrEmpty(mapping)))
                        {
                            if (a[0] == "__nodeName")
                                nameMapping = mapping;
                            else
                            {
                                mappings.Add(a[0], mapping);
                                LogHelper.Debug(a[0] + " " + mapping);
                            }
                        }
                    }
                }
    
                DocumentType dt = new DocumentType(dtId);
    
                if (dt != null)
                {
    
                    Document d = Document.MakeNew(nameMapping, dt, new umbraco.BusinessLogic.User(0), root);
    
                    foreach (Property p in d.getProperties)
                    {
    
                        try
                        {
    
                            if (mappings.ContainsKey(p.PropertyType.Alias))
                            {
                                if (p.PropertyType.Alias == "bodyText")
                                {
                                    string formattedField = mappings[p.PropertyType.Alias].Replace("\r\n\r\n","<br /><br />").Replace("\r\n","<br />");
                                    p.Value = formattedField;
                                }
                                if (p.PropertyType.Alias == "jobDatePosted" || p.PropertyType.Alias == "jobClosingDate")
                                {
                                    CultureInfo ukCulture = new CultureInfo("en-GB");
                                    var date = mappings[p.PropertyType.Alias];
                                    DateTime formattedDateTime = DateTime.Parse(date, ukCulture.DateTimeFormat);
                                    //var formattedDateTime = string.Format(date, "MM/dd/yyyy");
                                    p.Value = formattedDateTime;
    
                                }
                                if (p.PropertyType.Alias == "jobSector")
                                {
                                    // This is only here so I can check the mapping value. It contains the correct dropdown selected value, so why does it not save?
                                    var value = mappings[p.PropertyType.Alias];
                                    p.Value = value;
                                }
                                else
                                {
                                    p.Value = mappings[p.PropertyType.Alias];
                                }
                            }
    
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Debug(ex.ToString());
                        }
                    }
    
                    d.Save();
    
                    if (Publish == true.ToString())
                    {
                        d.Publish(new umbraco.BusinessLogic.User(0));
                        umbraco.library.UpdateDocumentCache(d.Id);
                    }
                }
                return WorkflowExecutionStatus.Completed;
            }
  • ianhoughton 281 posts 605 karma points c-trib
    Jan 15, 2014 @ 20:44
    ianhoughton
    0

    Still having this issue. Further investigation has shown that the correct dropdown value is in this table "cmsPropertyData"

    The Contour workflow completes ok, and the unpublished node gets created ok. When you first load the unpublished node all the field values are there apart from the dropdown values. Obviously if you then publish the node, it gets saved with empty values.

    The dropdowns are a standard Property Editor (Dropdown Lisr) set to Nvarchar.

    The Contour Entries view in the backend shows the correct values, so it's only when it creates the unpublished node.

    Any ideas?

    This is the latest code for getting the dropdown values and saving them.

    DocumentType dt = new DocumentType(dtId);
    
                if (dt != null)
                {
    
                    Document d = Document.MakeNew(nameMapping, dt, new umbraco.BusinessLogic.User(0), root);
    
                    foreach (Property p in d.getProperties)
                    {
    
                        try
                        {
    
                            if (mappings.ContainsKey(p.PropertyType.Alias))
                            {
                                switch (p.PropertyType.Alias)
                                {
                                    case "bodyText":
                                        string formattedField = mappings[p.PropertyType.Alias].Replace("\r\n\r\n","<br /><br />").Replace("\r\n","<br />");
                                        p.Value = formattedField;
                                        break;
                                    case "jobDatePosted":
                                    case "jobClosingDate":
                                        CultureInfo ukCulture = new CultureInfo("en-GB");
                                        var date = mappings[p.PropertyType.Alias];
                                        DateTime formattedDateTime = DateTime.Parse(date, ukCulture.DateTimeFormat);
                                        p.Value = formattedDateTime;
                                        break;
                                    case "jobSector":
                                        var sectors = GetPrevalues(1370);
                                        var jobSector = mappings[p.PropertyType.Alias];
                                        if (sectors.ContainsValue(jobSector))
                                        {
                                            var value = sectors.Single(x => x.Value.ToString() == jobSector).Value;
                                            p.Value = "<![CDATA[" + value + "]]>";
                                            //p.Value = value;
                                        }
                                        break;
                                    case "jobArea":
                                        var areas = GetPrevalues(1371);
                                        var jobArea = mappings[p.PropertyType.Alias];
                                        if (areas.ContainsValue(jobArea))
                                        {
                                            var value = areas.Single(x => x.Value.ToString() == jobArea).Value;
                                            p.Value = "<![CDATA[" + value + "]]>";
                                            //p.Value = value;
                                        }
                                        break;
                                    case "jobType":
                                        var types = GetPrevalues(1350);
                                        var jobType = mappings[p.PropertyType.Alias];
                                        if (types.ContainsValue(jobType))
                                        {
                                            var value = types.Single(x => x.Value.ToString() == jobType).Value;
                                            p.Value = "<![CDATA[" + value + "]]>";
                                            //p.Value = value;
                                        }
                                        break;
                                    default:
                                        p.Value = mappings[p.PropertyType.Alias];
                                        break;
                                }
                            }
    
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Debug(ex.ToString());
                        }
                    }
    
                    d.Save();
    
                    if (Publish == true.ToString())
                    {
                        try
                        {
                            d.Publish(new umbraco.BusinessLogic.User(0));
                            library.UpdateDocumentCache(d.Id);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Debug(ex.ToString());
                        }
                    }
                }
                return WorkflowExecutionStatus.Completed;
  • ianhoughton 281 posts 605 karma points c-trib
    Jan 16, 2014 @ 10:30
    ianhoughton
    101

    Fixed it with the help of this post on stackoverflow 

    I was trying to save the Text value of the dropdown list and not the ID, nothing to do with Contour.

    Snippet of modified code:

    case"jobSector":
         
    var sectors =GetPrevalues(1370);
         
    var jobSector = mappings[p.PropertyType.Alias];
         
    if(sectors.ContainsValue(jobSector))
         
    {
            p.Value
    = sectors.Single(x => x.Value.ToString()== jobSector).Key;
         
    }
         
    break;

     

     

     

     

  • Comment author was deleted

    Jan 16, 2014 @ 11:00

    Thanks for sharing the solution :)

Please Sign in or register to post replies

Write your reply to:

Draft