Hi everyone,
I experience some problems when I try to read eClass attributes and their values for some product.
I am using the new Java APIs and tried to do the following (I did this based on the example code from the ServiceMarketplace so probably the code looks familiar 😊 )
1] define the supporting resultDefinition...:
public ResultDefinition getSupportingProductResultDefinition() {
//Taxonomy lookup table
TableId classesTableId = prodRepositorySchema.getTableId("eClass");
FieldId[] classesFields = new FieldId[1];
classesFields[0] = prodRepositorySchema.getFieldId("eClass", "Name");
classesFields[0] = prodRepositorySchema.getFieldId("eClass", "eClass_Number");
classesFields[0] = prodRepositorySchema.getFieldId("eClass", "Identifier");
ResultDefinition rdClasses = new ResultDefinition(classesTableId);
rdClasses.setSelectFields(classesFields);
return rdClasses;
}
2] add the resultDefinition to some query... :
ResultDefinition lookupRD[] = new ResultDefinition[1]; lookupRD[0] = this.getSupportingProductResultDefinition(); RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(conn); limitingCommand.setSupportingResultDefinitions(lookupRD); // [ ... set session, search query and exectute the query ... ]
3] which brings me to printing the whole stuff to the console... :
[ this is the coding from PrintRecords.toConsole(RecordResultSet records) ]
...
MdmValue value = record.getFieldValue(fieldId);
System.out.print(fieldCode);
System.out.print(":t");
//Check if this is a lookup field
if(fieldProps.isLookup()) {
//If the field is a lookup, do not display the lookup id, but a sensible
//display value as defined in the lookup table.
String lookupDisplayValue = record.getLookupDisplayValue(fieldId);
System.out.println(lookupDisplayValue + "(" + value + ")");
if (fieldProps.isTaxonomyLookup()){
System.out.println(" --> field is taxonomy lookup. ");
AttributeId attributes[] = record.getAttributes(fieldId);
// print all attributes of the taxonomy field
for (int a=0; a<attributes.length;a++){
MdmValue attrValue = record.getAttributeValue(fieldId, attributes[a]);
System.out.println("'- " + attrValue);
}
}
}else {
System.out.println(value);
}
When I come to the eClass taxonomy field, I get the information that this is a tax field. But unfortunately, the
attributes[]
array is empty, although I definitely do have values for the attributes of this product.
The API now states that "If attributes were not populated then empty array is returned" How do I get these attributes? How can I "populate" them to my Java program?
Thanks for any help in advance!
Martin