November Happy Hour will be moved to Thursday December 5th.

Retrieving values from nested blocks

Vote:
 

Hi

i have form blocks added into a content area and i use the follwoing code to loop through each form item and retrieve the values. This works great!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private List<>string, string>> GetAllFields(ContentArea contentArea)
{
    var rtn = new List<>string, string>>();
 
    foreach (var item in contentArea.FilteredItems)
    {
        var formItem = item.GetContent() as IFormItem;
 
        if (formItem != null)
            rtn.AddRange(formItem.GetFieldValues(0));
    }
 
    return rtn;
}

however, i also have a text block inside the same content area which contains form blocks too. How can i retrieve the the field values of the form blocks nested inside the text block?

structure

form block

form block

form block

Text block

              form block

              form block   

form block

Any pointers will be greatly received

Paul

#121626
May 15, 2015 13:26
Vote:
 

How does "Text block" looks like?

#121640
May 16, 2015 22:53
Vote:
 

Hi Paul,

If the TextBlock have nested ContentArea property where FormBlocks could be stored, then try to used this property and call GetAllFieldsMethod recursively:

private List<KeyValuePair<string, string>> GetAllFields(ContentArea contentArea)
{
    var rtn = new List<KeyValuePair<string, string>>();
 
    foreach (var item in contentArea.FilteredItems)
    {
       var content = item.GetContent();

       var textBlock = content as TextBlock;
       if (textBlock != null)
       {          
          rtn.AddRange(GetAllFields(textBlock.ContentAreaProperty));
          continute;
       }

        var formItem = content as IFormItem;
 
        if (formItem != null)
            rtn.AddRange(formItem.GetFieldValues(0));
    }
 
    return rtn;
}
#121672
May 17, 2015 20:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.