cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API Question --Taxonomy field Attribute values

Former Member
0 Kudos

Hello MDM Gurus:

An MDM Java API question.

After a search I need to display list of Product table records (items) along with a taxonomy field attributes with values. How do I extract the attributes of a taxonomy field and it's values ?

I using the following command for getting Attribute IDs.

 AttributeId[] attribs = records<i>.getAttributes(taxonomyFldId);

and the following command for getting the Attribute value.

 MdmValue attribValue = records<i>.getAttributeValue(taxonomyFldId,attribs[j]);

But I do need to get the priority of the Attribute, I am going to display. How do I get it ?

There is one command,

   RetrieveAttributeLinksCommand ralCmd = new RetrieveAttributeLinksCommand(connectionAccessor);

But this command need the RecordId of the Taxonomy lookup table, not the main table record Ids which we got.

Appreciate your help.

Prasad Nutalapati

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

problem resolved !

i didi'nt set the "setSupportingResultDefinitions" option on RetrieveLimitedRecordsCommand with the taxonomy table

tks

Former Member
0 Kudos

Hi Diogo,

     Even i am trying the way just you followed to read the taxonomy field values from main table records, but when i am trying to set the setSupportingResultDefinitions but i am not getting idea how to set this result defintions array value and for which table do we need to get the resultdefinition object Please help me on this with some code, following is the code which i have




ResultDefinition resultDefinition = new ResultDefinition(schema.getTable(tableName).getId());



resultDefinition.setLoadAttributes(true);




RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = null;




resultDefinition.addSelectField(schema.getField(tableName,"MDM_ITEM_CODE").getId());



retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(myConnectionAccessor);



String session = null;




session = getAuthenticatedUserSession();



retrieveLimitedRecordsCommand.setSession(session);



retrieveLimitedRecordsCommand.setResultDefinition(resultDefinition);




retrieveLimitedRecordsCommand.execute();




RecordResultSet recordResults = retrieveLimitedRecordsCommand.getRecords();









FieldId fid1 = schema.getField(tableName,"GLOBAL_COMMODITY_CODE").getId();




AttributeId[] attId = retrieveLimitedRecordsCommand.getRecords().getRecord(i).getAttributes(fid1);

please let me know what else code i need to implement to get the taxonomy filed value from the main table record.

Thanks,

Ram.

Message was edited by: Ram Prasad

Former Member
0 Kudos

I have made this code to retrieve the FieldProperties

protected FieldProperties getFieldProperties(TableId tableId, FieldId fieldId){
		GetFieldListCommand getFieldListCommand = new GetFieldListCommand(conn);
		getFieldListCommand.setSession(userSession);
		getFieldListCommand.setTableId(tableId);
		try{
			getFieldListCommand.execute();
		}catch (Exception e){
			System.out.println(e);
		}
		FieldProperties[] fields = getFieldListCommand.getFields();
		for(int i = fields.length; i>0 ; i--){
			FieldProperties fProp = fields[i-1];
			if(fProp.getId().equals(fieldId)){
				return fProp;
			}
		}
		return null;
	}

this method is returning the correct fieldproperties ! i have debuged it yet, look the code below:

FieldProperties fieldProp = getFieldProperties(tableId, fieldId);
AttributeId[] attributIds = rec.getAttributes(fieldId);

here, when i call "rec.getAttibutes(fieldId)" it returns nothing !

in mine code i have the resultDefinition.setLoadAttibutes(true);

ResultDefinition res = new ResultDefinition(tableCode);
res.setLoadAttributes(true);
for(int i = fieldCodes.length;i>0;i--){
    res.addSelectField(fieldCodes[i-1]);
}
return res;

can u tell-me why i call "rec.getAttibutes(fieldId)" and it returns nothing ?

Former Member
0 Kudos

tks, but i have one question more,

"fieldProp", i think is a FieldProperties Object right ?

so .. how do i get this object ? because i didint use this object in my code

tks

Former Member
0 Kudos

Hi,

Sample code to display Taxonomy Attributes value.

if (fieldProp[j].isTaxonomyLookup()) 
						{
							AttributeId[] attributIds = resSet<i>.getAttributes(fieldProp[j].getId());
							for (int f = 0; f < attributIds.length; f++) 
							{
								MdmValue mdmVal = resSet<i>.getAttributeValue(fieldProp[j].getId(), attributIds[f]);
								lookupField = (LookupFieldProperties) fieldProp[j];
								TextAttributeValue txtVal = ((TextAttributeValue) mdmVal);
								System.out.println("Attribute txtVal = "+ txtVal);
								RetrieveAttributeCommand retAtt = new RetrieveAttributeCommand(connections);
								retAtt.setAttributeId(attributIds[f]);
								retAtt.setSession(sessionId);
								retAtt.setTaxonomyTableId(lookupField.getLookupTableId());
								try 
								{
									retAtt.execute();
								} catch (CommandException e) {
									e.printStackTrace();
								}
								TextAttributeProperties props = (TextAttributeProperties) retAtt.getAttribute();
								TextAttributeValueProperties[] val = props.getTextAttributeValues();
								for (int z = 0; z < val.length; z++) 
								{
									if (txtVal.getId().getIdValue() == val[z].getId().getIdValue()) 
									{
										System.out.println("Attribute Values = "+ val[z].getName());
									}
								}
							}
						}

In ResultDefinition remeber to load the attributes.

rdMain.setLoadAttributes(true);

Thanks,

Priya

Former Member
0 Kudos

Hi !

I think i have a similar problem .. i can't get the value from the taxonomy fields.

when i try to get the taxonomy field value i get Strings like "R1" "R2" "R3" ...

here is mine code to find in MDM:

"Schema.Produtos.TABLE" is the TableId

"Schema.Produtos.NOME" is a FieldID and is a text field

"Schema.Produtos.CATEGORIA" is a FieldId and is a taxonomy field.

                      //BUSCAR NA TABELA
		Search search = new Search(Schema.Produtos.TABLE);
		//NO CAMPO
		FieldSearchDimension fsdMaintableType = new FieldSearchDimension(Schema.Produtos.NOME);
		//O VALOR QUE CONTAINS
		TextSearchConstraint tscTypeRoot = new TextSearchConstraint(nome, TextSearchConstraint.CONTAINS);
		
		//ADICIONA PARAMETROS NA BUSCA
		search.addSearchItem(fsdMaintableType, tscTypeRoot);
		
		//DEFINE O RETORNO
		
		ResultDefinition resultDefinition = getResultDefinition(Schema.Produtos.TABLE, new FieldId[]{Schema.Produtos.NOME, Schema.Produtos.CATEGORIA});
		//EXECUTA A BUSCA
		RecordResultSet res = executeSearch(search, resultDefinition);

		//LOOP REGIOES 
		for(int iRegions = getRegions().length;iRegions>0;iRegions--){
			RegionProperties region = getRegions()[iRegions-1];
			//LOOP ROWS
			for(int iRows = res.getRecords().length;iRows>0;iRows--){
				Record rec = res.getRecord(iRows-1);
				
				//VERIFICAR SE EXISTE DESCRIÇÃO NO IDIOMA INFORMADO 
				
				if(rec.getMultiregionFieldValue(Schema.Produtos.NOME).containsRegion(region.getRegionCode())){
					System.out.println(rec.getMultiregionFieldValue(Schema.Produtos.NOME).getValue(region.getRegionCode()));
					System.out.println(rec.getFieldValue(Schema.Produtos.CATEGORIA));
					
					
				}
				
			}
		}

in this same code i have another problem .. i am trying to get all langueges descriptions .. but when i try to get the second language description .. has no values .. but on data manager .. i can see the other languages descriptions ...

can anyone helpme please ?

Former Member
0 Kudos

Hi Prasad,

You have almost solved it yourself! In the RetrieveAttributeLinksCommand() you need to set the two properties: setTaxonomyTableId() and setRecordId(), where recordID is the taxonomyFldId you have already found.

Good luck,

Walter