Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get TCM URI of a category for KeywordFieldDefinitionData type fields?

I want to fetch TCM URI of a category for KeywordFieldDefinitionData type fields.

I am using below link's code to read metadata fields of a component:-

https://code.google.com/p/tridion-practice/wiki/ChangeContentOrMetadata

I can see Category and CategoryFields properties in Reference.cs class(auto generated when refence to core service is given) but there is no property defined in Field class (defined in above code.google link) to access Category and CategoryFields properties . I have try to defined the property in following way :-

     public System.Reflection.PropertyInfo Category
    {
        get { return definition.GetType().GetProperty("Category", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); }
    }

Even above is not working, anyone of you guys please analyse this and reply.

Thanks in advance!

like image 359
SDL Developer Avatar asked Jan 25 '13 06:01

SDL Developer


1 Answers

You need to read the each SchemaField definition data and check if the Type is KeywordFieldDefinitionData and then get the Category information. Please see the below sample snippet.

SchemaFieldsData schemaFields = (SchemaFieldsData)_client.ReadSchemaFields(
               "tcmuriofschema", true, readOptions);
foreach (ItemFieldDefinitionData schemaField in schemaFields.Fields) {
   switch (schemaField.GetType().Name) {
      // handle other fields..
      // CategoryLink Fields
      case "KeywordFieldDefinitionData":
               KeywordFieldDefinitionData keywordTextSchemaField = (KeywordFieldDefinitionData)schemaField;
               string LinkedCategoryTitle =  keywordTextSchemaField.Category.Title;
               string LinkedCategoryId = keywordTextSchemaField.Category.IdRef;
               break;
      default:
               break;
   }
}
like image 124
Ram G Avatar answered Nov 07 '22 08:11

Ram G