4

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
              }
              }

2 Answers 2

3

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

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

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.

1
  • 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. Aug 1, 2014 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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