Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 17, 2013 @ 11:20
    Bo Damgaard Mortensen
    0

    Set value in custom hidden field in custom submit workflow

    Hi all,

    I have the following scenario: I've made a custom fieldtype from the Contour HiddenField webcontrol. This field is used for storing a GUID when the form has been submitted.

    My custom field type looks like this:

    public class CustomHiddenField: FieldType
        {
            public HiddenField TextField;
            public List<Object> Value;
    
            public CustomHiddenField()
            {
                this.Name = "Custom hidden field";
                this.Id = new Guid("3601C4F3-D7AB-4AC1-AF4A-80E477077EBB");
                this.Description =
                    "My custom hidden field";
                this.Icon = "hiddenfield.png";
                this.DataType = FieldDataType.String;
                TextField = new HiddenField();
    
            }
    
            public override System.Web.UI.WebControls.WebControl Editor
            {
                get
                {
                    TextField.Value = Value[0].ToString();
                    return TextField;
                }
                set
                {
                    base.Editor = value;
                }
            }
    
            public override List<object> Values
            {
                get
                {
                    Value.Clear();
                    Value.Add(TextField.Value);
                    return Value;
                }
                set
                {
                    base.Values = value;
                }
            }
    
            public override bool SupportsRegex
            {
                get { return true; }
            }
    
            public override string RenderPreview()
            {
                return "<input type=\"hidden\" />";
            }
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }
        }

    Then, I've created a custom workflow for setting the value in this field when the form has been submitted:

    public class CustomWorkflow: WorkflowType
        {
            public CustomWorkflow()
            {
                this.Name = "My custom workflow";
                this.Id = new Guid("B2A2BF39-261D-4C1F-BD6B-96D2C8D8C314");
                this.Description =
                    "My custom workflow";
            }
    
            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                // Try get the custom hidden field
                var customField =
                    record.RecordFields.FirstOrDefault(x => x.Value.Field.FieldTypeId.ToString().Equals("3601C4F3-D7AB-4AC1-AF4A-80E477077EBB"));
    // Check if the field was found in this collection if(customField.Value != null)
    { customField.Value.Values.Clear();
    customField.Value.Values = new List<object> {Guid.NewGuid().ToString().Replace("-", string.Empty)};
    var storage = new RecordStorage(); storage.UpdateRecord(record, e.Form); storage.Dispose(); return WorkflowExecutionStatus.Completed; } return WorkflowExecutionStatus.Cancelled; } public override List<Exception> ValidateSettings() { return new List<Exception>(); } }

    So basically, whenever a field of my custom hidden field is found, it sets its value to a new GUID (without the dashed, though)

    I've debugged my workflow code and it runs as it should, but there's no data in the field when I look at the entries in Contour. I've tried placing it in Submitted and Approved workflows, but without any result.

    Does anyone know why? :-)

    Thanks in advance,

    Bo

  • Comment author was deleted

    Jul 17, 2013 @ 11:53

    Hey Bo,

    Looks like you are missing a storage.UpdateRecordXml(record, e.Form); call, just place that after the storage.UpdateRecord(record, e.Form);

    Since the records viewer works on the xml it makes sense that it looked like it wasn't updated :)

  • Comment author was deleted

    Jul 17, 2013 @ 11:56

    And best to place it on the approved state to avoid it being overwritten again

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 17, 2013 @ 12:01
    Bo Damgaard Mortensen
    0

    Hi Tim,

    That sure did the trick! Thank you so much! :-) 

    All the best,

    Bo

  • Comment author was deleted

    Jul 17, 2013 @ 12:02

    Great, glad I could help :)

Please Sign in or register to post replies

Write your reply to:

Draft