Does old version of contour handle Forms data differently?
Hello all..
I have recently created a custom workflow that populates data from any given form to an e-mail. I made a switch statement in C# to handle the different field types, which is working absolutely fine.
However, I got another website where I need to implement the same kind of functionality but not getting the results as expected.
In both cases I have 2 dropdownlists which retrives its data from Umbraco Documents - Simply a Node containing some childnodes on the content tab like this:
Site
-- Companies
--- 1100 Company A -> txtstring email (property)
--- 1200 Company B -> txtstring email (property)
and so on..
So I got the list to show "1100 Company A" just like I did in the earlier project.. However, when I try to loop the Form's fields it cannot populate the actual selected data in the dropdownlist, only the "ID" even though I am using the excact same code as earlier.
I have debugged a lot and the code is not different from the "working" one it keeps populating the ID even though it "shouldnt".. Could it be something to do with the version of contour installed on the website?
I can say the package contour on the website (i cant see the version number on the backend) is 1.12 (which I reckon is quite old)
Anyways, I would appreaciate any help or thoughts in the subject.. Sample code to handle the population is as follows:
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) {
//List<object> list to hold the objects - listTwo contains the caption e.g. Postnummer, Date etc List<object> list = new List<object>(); List<object> listTwo = new List<object>(); foreach (RecordField rf in record.RecordFields.Values.OrderBy(f => f.Field.SortOrder)) {
if (rf.Values.Any() && rf.Values[0] != null && !string.IsNullOrWhiteSpace(rf.Values[0].ToString())) { //switch statement that checks whether the contour fields are equal to any of the listed ones. In that case, add the selected value to the List. switch (rf.Field.FieldType.ToString()) { case "Umbraco.Forms.Core.Providers.FieldTypes.RadioButtonList": case "Umbraco.Forms.Core.Providers.FieldTypes.CheckBoxList": case "Umbraco.Forms.Core.Providers.FieldTypes.DropDownList": case "Umbraco.Forms.Core.Providers.FieldTypes.Textarea": case "Umbraco.Forms.Core.Providers.FieldTypes.Textfield": case "Umbraco.Forms.Core.Providers.FieldTypes.CheckBox": case "Umbraco.Forms.Core.Providers.FieldTypes.DatePicker": string selectedId = rf.Values[0].ToString(); string selectedCaption = rf.Field.Caption; list.Add(selectedId); listTwo.Add(selectedCaption); break; }
I am not sure I understand what you mean by customize the fieldtype view - The contour form is basically just a created form with different fieldtypes. I really dont see the logic in it taking the ID, when I actually point at the value.. It is strange indeed. However, if there is an easier way to obtain the data from a dropdown list which data is being loaded from a prevalue source -> umbraco document etc. I would appreaciate it. Note that the thing I am doing (code above) might not be the correct way to do this :-)
Does old version of contour handle Forms data differently?
Hello all..
I have recently created a custom workflow that populates data from any given form to an e-mail. I made a switch statement in C# to handle the different field types, which is working absolutely fine.
However, I got another website where I need to implement the same kind of functionality but not getting the results as expected.
In both cases I have 2 dropdownlists which retrives its data from Umbraco Documents - Simply a Node containing some childnodes on the content tab like this:
Site
-- Companies
--- 1100 Company A -> txtstring email (property)
--- 1200 Company B -> txtstring email (property)
and so on..
So I got the list to show "1100 Company A" just like I did in the earlier project.. However, when I try to loop the Form's fields it cannot populate the actual selected data in the dropdownlist, only the "ID" even though I am using the excact same code as earlier.
I have debugged a lot and the code is not different from the "working" one it keeps populating the ID even though it "shouldnt".. Could it be something to do with the version of contour installed on the website?
I can say the package contour on the website (i cant see the version number on the backend) is 1.12 (which I reckon is quite old)
Anyways, I would appreaciate any help or thoughts in the subject.. Sample code to handle the population is as follows:
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
//List<object> list to hold the objects - listTwo contains the caption e.g. Postnummer, Date etc
List<object> list = new List<object>();
List<object> listTwo = new List<object>();
foreach (RecordField rf in record.RecordFields.Values.OrderBy(f => f.Field.SortOrder))
{
if (rf.Values.Any() && rf.Values[0] != null && !string.IsNullOrWhiteSpace(rf.Values[0].ToString()))
{
//switch statement that checks whether the contour fields are equal to any of the listed ones. In that case, add the selected value to the List.
switch (rf.Field.FieldType.ToString())
{
case "Umbraco.Forms.Core.Providers.FieldTypes.RadioButtonList":
case "Umbraco.Forms.Core.Providers.FieldTypes.CheckBoxList":
case "Umbraco.Forms.Core.Providers.FieldTypes.DropDownList":
case "Umbraco.Forms.Core.Providers.FieldTypes.Textarea":
case "Umbraco.Forms.Core.Providers.FieldTypes.Textfield":
case "Umbraco.Forms.Core.Providers.FieldTypes.CheckBox":
case "Umbraco.Forms.Core.Providers.FieldTypes.DatePicker":
string selectedId = rf.Values[0].ToString();
string selectedCaption = rf.Field.Caption;
list.Add(selectedId);
listTwo.Add(selectedCaption);
break;
}
}
}
Comment author was deleted
Yeah think there is a small difference when using fieldtypes that use prevalues and the value that get's stored
Do you have any idea on how to accomplish the before-written issue? Is there an easy way to retrieve the value from the dropdownlist? :)
Comment author was deleted
Yeah there should be a valuesAsString property that you can use
So just something like.. ValueAsString("id of dropdownlist here"); ? :-)
Comment author was deleted
think something like rf.ValuesAsString in your example code
Ah right.. Will give it a shot, thanks for your time, Tim
Sorry Tim, I am still getting the ID and not the actual text data :(
Comment author was deleted
Hmm that's strange, did you customize the fieldtype view?
I am not sure I understand what you mean by customize the fieldtype view - The contour form is basically just a created form with different fieldtypes. I really dont see the logic in it taking the ID, when I actually point at the value.. It is strange indeed. However, if there is an easier way to obtain the data from a dropdown list which data is being loaded from a prevalue source -> umbraco document etc. I would appreaciate it. Note that the thing I am doing (code above) might not be the correct way to do this :-)
Comment author was deleted
Will check why you get the id but as a temp workaround you can use
using (Umbraco.Forms.Data.Storage.PreValueStorage pvs = new Umbraco.Forms.Data.Storage.PreValueStorage()) {
var val = pvs.GetPreValue(newGuid(Country)).Value
}
is working on a reply...