Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I am reading all the Schemas using core service from the Building Block folder, after reading the schema, I am reading all the field from a particular Schema. I successfully get all the field from a particularly Schema, but i didn't find any method for get the field type in the "ItemFieldDefinitionData" class then how i get the field type.

i wrote following code for reading the schema and all the field.

   OrganizationalItemItemsFilterData f=new OrganizationalItemItemsFilterData();

    ArrayOfItemType ai=new ArrayOfItemType();
        List<ItemType> cpList =ai.getItemType() ;
        cpList.add(ItemType.SCHEMA);
       f.setItemTypes(ai);
        ArrayOfIdentifiableObjectData systemWideListSchema = client.getList("tcm:397-27454-2",f);

        System.out.println("in read");

        for (IdentifiableObjectData iod : systemWideListSchema.getIdentifiableObjectData()) 
            {
            SchemaData schemaData=(SchemaData)iod;
            System.out.println(schemaData.getTitle()+""+schemaData.getId());

               SchemaData sdata=(SchemaData) client.read(schemaData.getId(),new ReadOptions());
               SchemaFieldsData schemaFieldsData = client.readSchemaFields(sdata.getId(), false, null);
              ArrayOfItemFieldDefinitionData aFiled = schemaFieldsData.getFields();  
              List<ItemFieldDefinitionData> l= aFiled.getItemFieldDefinitionData(); 

              for(ItemFieldDefinitionData i:l)
              { System.out.println("in schema Filed");
                 System.out.println(i.getName());
              //Here i want to get the type of field
              }
              }
share|improve this question

2 Answers 2

up vote 3 down vote accepted

ItemFieldDefinitionData is the root class in the hierarchy:

ItemFieldDefinitionData
     ComponentLinkFieldDefinitionData
     DateFieldDefinitionData
     EmbeddedSchemaFieldDefinitionData
     ExternalLinkFieldDefinitionData
     KeywordFieldDefinitionData
     MultiLineTextFieldDefinitionData
     MultimediaLinkFieldDefinitionData
     NumberFieldDefinitionData
     SingleLineTextFieldDefinitionData
     XhtmlFieldDefinitionData

So you can get the exact class with GetType, like i.GetType().Name, for example. This will return you the underlying class, which corresponds to the field type, for instance DateFieldDefinitionData

share|improve this answer
    
Thanks @user978511 by using the method getClass() i get instance of particually field Type class –  pankaj Sharma Aug 1 at 7:41
    
You can also do a strongly-typed check by using something like "if (i is MultiLineTextFieldDefinitionData) { ... }" –  Peter Kjaer Aug 1 at 13:53
    
Yes, but he wanted to print out the field type –  user978511 Aug 1 at 13:56

For this kind of work, you should definitely look at the Change Content or Metadata recipe in the Tridion Cookbook. There you will find a very useful library that exposes, among other things, the field types.

share|improve this answer
    
Update: user978511 and I seem to have posted simultaneously... so for clarity - the library I mentioned exposes the type as a property, and you still have to read the name yourself, so it's really the same technique. Even so, I'd still check out the library. –  Dominic Cronin Aug 1 at 7:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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