on 08-26-2009 8:28 PM
I am having trouble getting the values of attributes when the attribute is multi-valued.
Here is the excerpt from my code:
RecordResultSet rs = retrieveLimitedRecordsCommand.getRecords();
for(int i=0; i < rs.getCount(); i++)
{
Record record = rs.getRecord(i);
FieldId taxonomyField = repository.getFieldId("Products", "Category");
AttributeId[] attrsIds = record.getAttributes(taxonomyField);
if( attrsIds != null && attrsIds.length> 0 )
{
for( int j=0; j<attrsIds.length; j++)
{
AttributeProperties properties = as.getAttribute(taxonomyField, attrsIds[j]);
String strAttributeName = properties.getName().toString();
String strAttributeValue = "";
String strDimentions = "";
switch(properties.getType())
{
case AttributeProperties.NUMERIC_TYPE:
//To be completed later
break;
case AttributeProperties.TEXT_TYPE:
MdmValue mdmVal = record.getAttributeValue(taxonomyField, attrsIds[j]); //Cannot be cast into MultiValue
TextAttributeValueId t = new TextAttributeValueId( attrsIds[j].getIdValue() );
TextAttributeValueEx tav = new TextAttributeValueEx( t, repository.getTableId("Categories"), attrsIds[j], sessionContext );
tav.getDisplayValue(); //Gets the display name for single values, not multi !!
break;
}
}
}
}
The trick is to cast the getAttributeValue method into a MultiValue object:
MultiValue attributeValues = (MultiValue) record.getAttributeValue(taxonomyField, attrsIds[j]);
for(int k=0; k<attributeValues.getValuesCount(); k++)
{
TextAttributeValueId t = new TextAttributeValueId( attributeValues.getValue(k).toString() );
TextAttributeValueEx tav = new TextAttributeValueEx( t, repository.getTableId("Categories"), attrsIds[j], sessionContext );
strAttributeValue += (tav != null && !tav.isNull()) ? tav.getDisplayValue() : "NULL";
strAttributeValue += ", ";
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.