cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving values from Hierarchical Lookup table

Former Member
0 Kudos

Hi,

I am trying to retrieve values from Hierarchical lookup table, Can someone explain how to do this using Java2 API. This hierarchy field is not in main Customer table.

I am able to retrieve values of Lookup table by doing like this. Is retreiving hierarchy values is also on the same lines. Please let me know.

ResultDefinition rdLookup =new ResultDefinition(countryTableId);

rdLookup.addSelectField(new FieldId(repSchema.getFieldId("Countries", "Country_Name")));

rdLookup.addSelectField(new FieldId(repSchema.getFieldId("Countries", "ISO_Code_2")));

ResultDefinition[] rdArray = new ResultDefinition[2];

rdArray[0] = rdLookup;

RetrieveLimitedRecordsCommand ret=new RetrieveLimitedRecordsCommand(simpleConnection);

ret.setSearch(s);

ret.setSession(userSession);

ret.setResultDefinition(rd); //assigned the resultdefinition to retrieve limited records command

try{

ret.execute();

}catch(Exception e){

}

RecordResultSet rs=ret.getRecords();

Record r=rs.getRecord(i);

Record[] recCountryLookup = r.findLookupRecords(repSchema.getFieldId("Customers", "Country"));

if(recCountryLookup != null){

Record recCountry = recCountryLookup[0];

strCustomerCountry = recCountry.getFieldValue(repSchema.getFieldId("Countries", "Country_Name")).toString();

}

Thanks

-Sai

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Thanks for the info. But my requirement is to update child nodes of hierarchy tables especially the start dates and I have to change in leaf nodes. So basically I need to lookup hierarchy tables and then update the values in the child leaf nodes.

any pointers to the above requirement.

Thanks

-Sai

Former Member
0 Kudos

Hi,

This is similar to the modify record process.

Retrieve the data from Hierarchy lookup table as you do it for main table, and then modify the records in hierarcy table using ModifyRecordCommand.

Only thing you need to take care is pass the parent id....

In you want to retrieve the data in a hiearchy structure then use the command,

RetrieveLimitedHierTreeCommand retHierTree = new RetrieveLimitedHierTreeCommand(connections);
retHierTree.setSession(sessionId);
retHierTree.setSearch(ser);
retHierTree.setResultDefinition(rdHierLookup);

Hope this helps.

Thanks,

Priya.

Former Member
0 Kudos

Hi,

I am not able to get the hierarchy table values for the main table. Also if I have several tables that I have to look for like... from 2 Flat tables and 2 hierarchy tables, how do I that.

How do I get this resSet in the below statements.

// Lookup Value:

System.out.println("Lookup Id : "+ resSet<i>.getFieldValue(fieldProp[j].getId()));

System.out.println("Lookup Value : "+ resSet<i>.getLookupDisplayValue(fieldProp[j].getId()));

If you have any sample with RetrieveLimitedHierarchCommand that would be helpful.

Thanks

-Sai

Former Member
0 Kudos

Hi,

I donot have a specific example for Hierarchy lookup table.

You can refer to any lookup table example, as hierarchy table also behaves in the same way.

The resSet is the record set, that are retireved using RetrieveLimitedCommand.

As resSet is an array of records, we will have to put it in a loop.

Thanks,

Priya.

Former Member
0 Kudos

Hi,

Consider Hierarchy table also as a lookup table and retrieve value from it similar to lookup table.

Please find some sample code.

ResultDefinition rdMain = new ResultDefinition(new TableId(tabProp.getId()));
// Array List for defining Lookup Fields Result set.
List<ResultDefinition> resultDefinitionList = new ArrayList<ResultDefinition>();
ResultDefinition rdlookup = new ResultDefinition(new TableId(lookupField.getLookupTableId()));
FieldProperties[] fieldlookupProp = retId.retrieveFieldIds(connections, sessionId, lookupField.getLookupTableId());
for (int h = 0; h < fieldlookupProp.length; h++) 
{
	rdlookup.addSelectField(new FieldId(fieldlookupProp[h].getId()));
}
resultDefinitionList.add(rdlookup);
rdMain.setLoadAttributes(true);
// Defining the Result set array for the Lookup Tables.
ResultDefinition[] lookupValues = (ResultDefinition[]) resultDefinitionList.toArray(new ResultDefinition[resultDefinitionList.size()]);

RetrieveLimitedRecordsCommand recordsCommand = new RetrieveLimitedRecordsCommand(connections);
recordsCommand.setSession(sessionId);
recordsCommand.setSearch(ssearch);
recordsCommand.setResultDefinition(rdMain);
recordsCommand.setSupportingResultDefinitions(lookupValues);

Record [] recs = recordsCommand.getRecords().getRecords();


// Lookup Value:
System.out.println("Lookup Id : "+ resSet<i>.getFieldValue(fieldProp[j].getId()));
System.out.println("Lookup Value : "+ resSet<i>.getLookupDisplayValue(fieldProp[j].getId()));

Thanks,

Priya