cancel
Showing results for 
Search instead for 
Did you mean: 

Lookup tables using java API

Former Member
0 Kudos

Hi,

How to retrieve lookup table values using MDM java API.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jyothi,

Check the below code

TableId lookupTableId = repositorySchema.getTableId("Test_Lookup");

FieldId[] lookupFields = new FieldId[2];

lookupFields[0] = repositorySchema.getFieldId("Test_Lookup", "Name");

lookupFields[1] = repositorySchema.getFieldId("Test_Lookup", "Code");

ResultDefinition rd = new ResultDefinition(lookupTableId);

rd.setSelectFields(lookupFields);

RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(simpleConnection);

retrieveLimitedRecordsCommand.setSession(authenticateUserSessionCmd.getSession());

retrieveLimitedRecordsCommand.setResultDefinition(rd);

try

{

retrieveLimitedRecordsCommand.execute();

totalRecord = retrieveLimitedRecordsCommand.getRecords().getCount();

}

Regards,

Jitesh Talreja

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Jyothi,

Please find smaple code below

UserSessionContext context = new UserSessionContext(serverName,repositoryName,defaultLang,username);*

SessionManager session = SessionManager.getInstance();

String userSession = session.createSession(context, SessionTypes.USER_SESSION_TYPE, password);

MetadataManager metadataManager = MetadataManager.getInstance(); metadataManager.registerDataNotifications(context, password);

RepositorySchemaEx repositorySchema = metadataManager.getRepositorySchema(context);

//Retrieve Lookup table Data

TableSchema tableSchema = repositorySchema.getTableSchema(tableName);

ResultDefinition resultDef = new ResultDefinition(tableSchema.getTable().getId());

resultDef.setSelectFields(tableSchema.getFieldIds());

try {

RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(context);

limitingCommand.setResultDefinition(resultDef);

limitingCommand.execute();

} catch (SessionException e) {

} catch (ConnectionException e) {

} catch (CommandException e) {

} *

// Result Set

RecordResultSet resultSet = limitingCommand.getRecords();

Record [] records = resultSet.getRecords();

for (int i = 0; i < records.length; i++) {

Record record = records<i>;

System.out.println("Record ID: "+ record.getId());

System.out.println("Code Field Value: "+

record.getFieldValue(tableSchema.getFieldId(u201CCodeu201D)).toString());

System.out.println("Description Field Value: "+

record.getFieldValue(tableSchema.getFieldId (u201CDescriptionu201D)).toString());

}

Thanks,

Veeru.

Former Member
0 Kudos

i think the blog is based on MDM4j. Can somebody give me the code sample for the same.

Thanks.

Greg_Austin
Active Participant
0 Kudos

Hi jyothi,

You can search the lookup tables the same way you search the main table with the RetrieveLimitedRecordsCommand, passing the lookup TableId to the Search object and ResultDefinition object that the command uses. If you want all of the values just pass the command a Search object with no constraints.

-Greg

Former Member
0 Kudos

Hi,

You can also refer

http://help.sap.com/javadocs/MDM/SP06P2/index.html

Regards

Nisha

Former Member
0 Kudos

Hi Jyothi,

Refer /people/anand.chandrashekar/blog/2006/05/27/populating-lookup-fields-using-java-api

Hope it helps.

Thanks,

Minaz