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.
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:
Then, I've created a custom workflow for setting the value in this field when the form has been submitted:
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
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
And best to place it on the approved state to avoid it being overwritten again
Hi Tim,
That sure did the trick! Thank you so much! :-)
All the best,
Bo
Comment author was deleted
Great, glad I could help :)
is working on a reply...