Accessing an Embedded Schema field Definition in a C# TBB

January 22nd, 2018 | Posted by Robert Curlette in .NET | Tridion

While creating some JSON for the Metadata on a Structure Group in C# I came across an interesting challenge to display the URI and Title of the Embedded Schema. Initially I was using a FieldDefinition instead of an EmbeddedFieldDefinition and then the ID and Title properties were not available of the Embedded Field. Casting the variable to an EmbeddedSchemaFieldDefinition was the proper way to access the EmbeddedField definition info.

 

EmbeddedSchemaField right1Field = pageMetaFields[fieldName] as EmbeddedSchemaField;
EmbeddedSchemaFieldDefinition def = right1Field.Definition as EmbeddedSchemaFieldDefinition;

embeddedSchemaFieldDef.RootElementName = def.EmbeddedSchema.RootElementName; //"Content";
embeddedSchemaFieldDef.Id = def.EmbeddedSchema.Id; // "tcm:11-123-8";
embeddedSchemaFieldDef.Title = def.EmbeddedSchema.Title; // "Metadata fieldname";

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

Leave a Reply

Your email address will not be published. Required fields are marked *