on 02-09-2009 2:33 PM
Hi,
I have a main table which has taxonomy field,for ex: category.
Main table: Products which has ProductName(text),ProductNo(text),Category fields(Lookup[taxnomoy])
Could anyone please tell me how to retrieve the records and attributes from a taxonomy table.
Please provide some sample codes.
Thanks
Sabari
Hi Sabari,
your question is not so clear- any way find the following example
if you want to get records based on search criteria( ex: taxonomy values where ProductName = "something "),, follow the below steps;
1 . build Search Object- ( I guess you know this step)
2. get RecordResultSet Object -
Example
//Compose array of the fields to retrieve
FieldId[] fields = new FieldId[5];
fields[0] = assign FiledId of Category field ;
//Create the result definition for the search table
ResultDefinition rd = new ResultDefinition(productsTableId);
rd.setSelectFields(fields);
// Retrive ResultSet
RetrieveLimitedRecordsCommand recordsCommand = new
RetrieveLimitedRecordsCommand(mdmConnection.getConnection());
recordsCommand.setSession(mdmConnection.getAuthenticatedUserSession().getSession());
recordsCommand.setResultDefinition(rd);
recordsCommand.setSearch(search);
recordsCommand.execute();
RecordResultSet records= recordsCommand.getRecords();
3 . Now Iterate through resultSet for CategoryRecord lookUp Id
Record record = records.getRecord( i );
FieldId[] fieldIds = record.getFields();
for(int n=0; n<fieldIds.length; n++) {
FieldId fieldId = fieldIds[n];
FieldProperties fieldProps = records.getRecordMetadata().getField(fieldId);
String fieldCode = fieldProps.getCode();
MdmValue value = record.getFieldValue(fieldId);
if(fieldCode.equals("Category")) {
if (!(value instanceof NullValue)) {
//LookupValue appLookUpValue = (LookupValue) value;
Record[] lookupRecord=record.findLookupRecords(fieldId);
if(lookupRecord!=null && lookupRecord.length>0)
{
populate for a category for every lookup record
// cat=this.getCategory(lookupRecord[0].getId(),locale);
}
}
}
Note:- from Main table records , you will get Category lookup records, you need to look up for every Category lookUp Record; there may be number of Category records for one main table Record;
if you still face problem , let me know;
Regards
Rajasekhar k
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi RajSekhar,
The information which you provided helped me to understand the lookup on taxonomy.
Let me give you the exact info i needed.
Main table:Products
Fields:ProductNo,ProductName,Category(Lookup[taxonomy])
I am able to retreive,create,modify record using MDM client-data manager(MDM5.5).
i.e ProductNo22,ProductNameCamera,-DigitalCameras,Samsungcamera for 3 feilds respectively
sample taxonomy table(Category) data:
-ElectoronicProducts
-TV
-SamsungTV
-LGTV
-onidatv
-LAPTOP
-Dell
-Sony
-DigitalCameras
-Sony
-Samsungcamera
-FoodProducts
-Microven
-Samsung
-LG
-lotex
-Refrigirator
-whirlpool
-LG
-Onida
Here ElectornicProducts and FoodProducsts are categories. TV,LAPTOP,digitalcameras,microoven,refridgirator are sub categories.
For every products there could be different attributes for ex:LGTV AND ondiatv the attributes like width,height,weight could vary.
My question:
How to retreive data from taxonomy table with attributes using MDM java api5.5. I need sample code to retreive the data from taxonomy table.
Thanks
Sabari
Edited by: Sabarinathan Selvaraj on Feb 10, 2009 7:28 AM
Hi
Given that you have retrieved the Record id and the TaxonomyTableId,
Try using the following code:
LinkedHashMap hmAttributeLinks = null;
RetrieveAttributeLinksCommand objRetrieveAttributeLinksCommand = new RetrieveAttributeLinksCommand(objConnectionManager.getConnectionAccessor());
objRetrieveAttributeLinksCommand.setSession(objConnectionManager.getUserSessionID());
objRetrieveAttributeLinksCommand.setIncludeAncestors(true);
objRetrieveAttributeLinksCommand.setTaxonomyTableId( new TableId( strTaxomonyTableID ));
objRetrieveAttributeLinksCommand.setRecordId( new RecordId( strRecordId ));
objRetrieveAttributeLinksCommand.execute();
if( objRetrieveAttributeLinksCommand.getAttributeLinks() != null
&& objRetrieveAttributeLinksCommand.getAttributeLinks().length > 0)
{
hmAttributeLinks = new LinkedHashMap();
for(int iAttributeCount =0 ; iAttributeCount < objRetrieveAttributeLinksCommand.getAttributeLinks().length; iAttributeCount++)
{
RetrieveAttributeCommand objRetrieveAttributeCommand = new RetrieveAttributeCommand(objConnectionManager.getConnectionAccessor());
objRetrieveAttributeCommand.setAttributeId( objRetrieveAttributeLinksCommand.getAttributeLinks()[iAttributeCount].getId());
objRetrieveAttributeCommand.setSession(objConnectionManager.getUserSessionID());
objRetrieveAttributeCommand.setTaxonomyTableId(new TableId(strTaxomonyTableID));
objRetrieveAttributeCommand.execute();
if( objRetrieveAttributeCommand.getAttribute() instanceof TextAttributeProperties)
{
HashMap hmAttributeProperties = new HashMap();
HashMap hmValueProperties = new HashMap();
TextAttributeProperties objTextAttributeProperties = (TextAttributeProperties) objRetrieveAttributeCommand.getAttribute();
//Putting the Attribute ID and Attribute VALUE
hmAttributeProperties.put( objRetrieveAttributeCommand.getAttribute().getId().toString(),
objRetrieveAttributeCommand.getAttribute().getName().get(strStandardLanguage));
for(int iCount = 0; iCount < objTextAttributeProperties.getTextAttributeValues().length; iCount++)
{
TextAttributeValueProperties objTextAttributeValueProperties = objTextAttributeProperties.getTextAttributeValue(iCount);
//Putting the Value ID and Value NAME
hmValueProperties.put( objTextAttributeValueProperties.getId().toString(),
objTextAttributeValueProperties.getName().get(strStandardLanguage));
}
//Putting the Attributes and Values hashmaps
hmAttributeLinks.put( hmAttributeProperties, hmValueProperties);
}
}
return hmAttributeLinks;
}
Cheers!!
hi
you can go with following code....
data: begin of t_table occurs 0,
productname type main-productname,
ProductNo type main-ProductNo,
catagory type main-catagory,
end of t_table.
select productname
productno
catagory
from main
into table t_table.
if sy-subrc = 0.
loop at t_table.
write: / t_table-productname,t_table-productno,t_table-catagory.
endloop.
endif.
regards
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.