on 01-04-2008 10:43 AM
Hello everyone,
I want to get all linked attribute values of a taxonomy field. Currently I can get values of all linked attribute which have 'ratings' is 'Normal'. I cannot get the value of linked attribute which have 'ratings' is 'Minimum' and 'Maximum'. Its type is 'Numeric'. When I tried to get its value by using record.getAttributeValue(fieldId, attributeId), this command throw an exception:
java.lang.IllegalArgumentException: Attributes 'A283_27843' is not exist or is not linked to taxonomy field 'F24_29'
I already knew that if one attribute is empty, this command will throw that exception. But I am quite sure that this linked attribute has value (I can see its value in Data manager). In data manager I saw:
Spannbereich \[Min\] = 1
Spannbereich \[Max\] = 9.89
'Spannbereich' is the attribute name.
Does anyone know how to solve this problem? I used Java API and MDM 5.5
Thank you very much!
Once you have the AttributeProperties array, you can extract the Text Values, if your attribute is Type Text, with this code, which complements the previous.
TextAttributeValueProperties[] textAttributeValueProperties =
((TextAttributeProperties) mdmAttributes<i>)
.getTextAttributeValues();
for (int ii = 0, jj = textAttributeValueProperties.length;
ii < jj;
ii++) {
textAttributeValueProperties[ii]
.getId()
.getIdValue();
textAttributeValueProperties[ii]
.getName()
.toString();
}
Hope this helps.
BR.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wulfrano,
Yes, your code can get all values for a TextAttributeProperties. But your code get all values that a TextAttributeProperties can have, not the current value of it. You must get its value first (MdmValue) then use this code: TextAttributeValueId textValId = value.getId();. In the loop you compare if (textValId.getIdValue() == textAttributeValueProperties\[ii\].getId().getIdValue()), then you use textAttributeValueProperties\[ii\].getName().
You have to make the AttributeLink Array an AttributeProperties. Like this:
RetrieveAttributeLinksCommand cmd = new RetrieveAttributeLinksCommand(connection);
cmd.setSession(userSession);
cmd.setTaxonomyTableId(taxonomyTableID);
cmd.setRecordId(taxonomyRecordID);
try {
cmd.execute();
} catch (CommandException e) {
e.printStackTrace();
}
AttributeLink[] als = cmd.getAttributeLinks();
AttributeProperties[] attributes = new AttributeProperties[als.length];
for(int i=0, j=als.length; i<j; i++) {
attributes<i> = getAttribute(connection, userSession, taxonomyTableID, als<i>.getId());
}
Check also the javadoc for AttributeProperties Interface [help.sap.com/javadocs/MDM/SP04/com/sap/mdm/schema/AttributeProperties.html]
Please let me know if this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wulfrano,
Thank you for your reply.
I can get all AttributeProperties, but the problem I posted in this thread is I cannot get the value of attribute. Only attribute that has 2 types of ratings I cannot get its value. The method "getAttribute", I cannot find it in SAP javadoc. I used RetrieveAttributeCommand to retrieve AttributeProperties for each als\[i\]. Your code can get AttributeProperties only, it cannot get attribute value.
Regards,
I was able to get this working. Here is the code I used. Hopefully it will help you as well.
//Loop through all the records in the result
for (int i = 0; i < records.getCount(); i++) {
Record record = records.getRecord(i);
RecordId recId = record.getId();
System.out.println(record.getDisplayValue());
System.out.println("----
");
FieldId[] fieldIds = record.getFields();
//Print out the attributes
FieldId attFieldId = attFiledId;
AttributeId[] attributes = record.getAttributes(attFieldId);
for (int m = 0; m < attributes.length; m++) {
AttributeId id = attributes[m];
String attValues = "";
try {
//Get values
attValues =
getAttributeValues(id, record, conn, session);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("attValue = " + attValues);
}
}
********************************************************************************
private static String getAttributeValues(
AttributeId aid,
Record rec,
ConnectionAccessor conn,
String session)
throws Exception {
String retorno = "";
MdmValue mdmVal = rec.getAttributeValue(new FieldId("F24_29"), aid);
if (!mdmVal.isMultivalue()) {
if (mdmVal.getType() == MdmValue.Type.TEXT_ATTRIBUTE) {
TextAttributeValue txtVal = ((TextAttributeValue) mdmVal);
AttributeId id = aid;
RetrieveAttributeCommand retAtt =
new RetrieveAttributeCommand(conn);
retAtt.setAttributeId(id);
retAtt.setSession(session);
retAtt.setTaxonomyTableId(new TableId("T5"));
try {
retAtt.execute();
TextAttributeProperties props =
(TextAttributeProperties)retAtt.getAttribute();
TextAttributeValueProperties[] val =
props.getTextAttributeValues();
for (int i = 0; i < val.length; i++) {
if (txtVal.getId().getIdValue()
== val<i>.getId().getIdValue()) {
retorno = val<i>.getName().toString();
}
}
} catch (CommandException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return retorno;
}
Hi Sarah,
Your code cannot get the value of an attribute of which 'ratings' is not 'normal'. For example, 'ratings' of attribute 'Size" are 'Minimum' and 'Maximum' (i.e in mdm manager you will see Size\[Min\] = xx and Size\[Max\] = yy). If you use record.getAttributeValue() with attribute 'Size', it will throw exception although record.getAttributeValue() only throws exception when the attribute doesn't have any value.
Regards,
Hi, you need to use the RetrieveAttributeLinksCommand in order to extract the Attributes, you can find more info Link: [http://help.sap.com/javadocs/MDM/SP04/com/sap/mdm/data/commands/RetrieveAttributeLinksCommand.html]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I have already used that command. First, I use RetrieveAttributeLinksCommand, then I get AttributeLink[] attributeLinks = RetrieveAttributeLinksCommand.getAttributeLinks(). After that I can get AttributeId from AttributeLink, and then its value by using record.getAttributeValue(taxonomyFieldId, AttributeId). This command has the problem that I posted in this read.
Hi Luan,
Check that you are passing a value of type String but value required is of type Int thats why its throwing illegalArgument Exception.
Please check with your argument passed to used function.
Please reward if found helpful.
Regards
Alok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.