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!
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With