3

I have three Schema A (Content) , B(Embedded), C(Embedded)

Schema A have fields A1(text) and A2(EmbeddedSchema)

Schema B have fields B1(EmbeddedSchema), B2(text) And Schema C have fields C1(text) and C2(text)

Schema B is embedded with field A2 and Schema C is embedded with field B1.

How to get the value of C1 field in C# TBB/Fragment.

I am doing to get the value of field A2 (document_order) with below code but unable to get the in field C1

if (pubMetadata.Contains("order_sort"))
{    
    foreach (ItemFields docsort in ((EmbeddedSchemaField)pubMetadata["order_sort"]).Values) 
    {
        //Below code line works 
        string docOrder = ((KeywordField)docsort["document_order"])
                              .Value.Description.ToString();

        //Below code line is not working 
        string docSortName = ((KeywordField)docsort["doc_sort"])
                                 .Value.Description.ToString();                   
    }

}
1
  • Can you please share your actual schema definitions? It's difficult to map your code to your abstract explanation.
    – Ant P
    Commented Apr 29, 2014 at 15:26

1 Answer 1

2

The general pattern is that the value of an EmbeddedSchemaField is an ItemFields collection.

So, something along these lines should work (I didn't test this)

ItemFields fields = new ItemFields(Component.Content, Component.Schema);
EmbeddedSchemaField embedded1 = (EmbeddedSchemaField)fields["EmbeddedSchemaFieldName"];
ItemFields embeddedFields = embedded1.Value;
EmbeddedSchemaField embedded2 = (EmbeddedSchemaField)embeddedFields["EmbeddedSchemaField2Name"];
ItemFields embeddedFields2 = embedded2.Value;

Pay attention to multi-value Embedded Schema fields, and all else failing, use the DGX extension from c# Building Blocks.

1
  • Thanks Nuno. Dreamweaver Get Extension meets my requirement.
    – user584
    Commented Apr 30, 2014 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.