I have an embedded schema for a STUB component metadata field which has 4 fields and marked as "Allow Multiple Values", along-with other fields in SDL Tridion. I am using SDL Tridion Web 9.0.

The STUB component metadata is blank initially. I am using a save event handler in SDL Tridion to populate this metadata from External Metadata of ECL component. I am using EmbeddedSchemaField to hold initial metadata field for the embedded field, but I am unable to populate the ItemFields inside the EmbeddedSchemaField while saving. I am using the following code to initially hold blank field from collection of metadata Fields of my component.

_images = ((EmbeddedSchemaField)metadataFields["Images"]);

where metadataFields is the metadata fields collection.

While trying to add values to the ItemFields inside, I am trying to use

IList<ItemFields> _imagesFields = _images.Values;

but it gives me Count = 0. So I am unable to do anything with this any further. Any suggestions/hints will be very very appreciated.

1 Answer 1


EmbeddedSchemaField.Values is a collection of ItemFields objects (one for each value). If you have an optional embedded field, it will initially not have any values, so indeed EmbeddedSchemaField.Values.Count = 0

You can add values to the collection, though:

Schema embeddedSchema = ((EmbeddedSchemaFieldDefinition)embeddedField.Definition).EmbeddedSchema;
ItemFields embeddedFields = new ItemFields(embeddedSchema);
  • Thanks! But how do I get the embeddedSchema? Sorry may be I sound foolish here but this is what I did: ItemFields metadataFields = new ItemFields(subject.Metadata, subject.MetadataSchema); where subject is my STUB component. and then I tried to capture the optional Images field, which is the embedded schema field as _images = ((EmbeddedSchemaField)metadataFields["Images"]); So how should I get the emdedded schema of this field?
    – Sankar
    Oct 8, 2020 at 8:32
  • I have updated the example to make this clear. Oct 8, 2020 at 19:17
  • Hello Rick, thanks for updating. However, I have used ItemFields to get all metadata fields and ItemFieldDefinition does not contain any definition of EmbeddedSchema. So your example is not working for me. This is my code snippet: private EmbeddedSchemaField _images; //Get metadata XML for stub component first ItemFields metadataFields = new ItemFields(subject.Metadata, subject.MetadataSchema); _images = ((EmbeddedSchemaField)metadataFields["Images"]); Can you please advise?
    – Sankar
    Oct 9, 2020 at 5:03
  • Updated the example again. :-) I’m sorry, I currently can’t check if the code compiles, but this is the general idea. Oct 9, 2020 at 9:54
  • Thanks a lot Rick. It works!!
    – Sankar
    Oct 9, 2020 at 12:32

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.