cancel
Showing results for 
Search instead for 
Did you mean: 

Get linked attribute values?

Former Member
0 Kudos

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!

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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().

Former Member
0 Kudos

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.

Former Member
0 Kudos

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,

Former Member
0 Kudos

Hey Bui,

Did you solved your problem?

Thanks,

Raags

Former Member
0 Kudos

Hi Raags,

I haven't solved my problem yet. I sent my code to SAP consultant so that they can take a look. I hope that they can solve it.

Former Member
0 Kudos

Hi Bui,

Thanks for responding!! I request you to let us know when you get solution from SAP/Others. I appreciate your help!!

Thanks,

Raags

Former Member
0 Kudos

Hi Luan,

Did you hear anything back from SAP yet? Hopefully they are able to resolve this for all of us.

Former Member
0 Kudos

Hi all,

I haven't heard anything from SAP yet. If they have replied me, I will post the answer here.

Former Member
0 Kudos

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;

}

Former Member
0 Kudos

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,

Former Member
0 Kudos

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]

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Alok,

The type of attributeId I passed is AttributeId, not String. If I passed wrong type, that code cannot be compiled and run. The value 'A283_27843' you see in exception line, the IDE uses toString() method to display it.

Regards,

Luan