cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API create lookup record

Former Member
0 Kudos

Hi All,

I am trying to update existing record but I am not getting how to change the lookup field so can any one tell me how we can do this.

Thanks

Ninad

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

I assume you are talking about changing the value of a field that is of type Lookup [Flat]? If so when you are setting the fields new value you give a LookupValue type. The constructor of LookupValue takes a RecordId of the table the field looks up to. You can get the correct RecordId by doing a search on the lookup table and using the .getId() method on the correct Record.

Former Member
0 Kudos

hi Greg,

how can i fetch data from lookup table? Is there any easy way to fetch all records from lookup table or I have to follow the same way we search main table?

Thanks

Ninad

Former Member
0 Kudos

Hi ninad,

Use this commands to fetch all data from Lookup table.

You need to fetch

// Retrive all records from Look up table

RetrieveLimitedRecordsCommand recList = new RetrieveLimitedRecordsCommand(connection);

// Get the Look up field props by type casting to List of fields props of maintable

LookupFieldProperties lf = (LookupFieldProperties) cfid<i>;

rd = new ResultDefinition(lf<i>.getLookupTableid());

rd.setSelectFields(fid);

Search search = new Search(lf<i>.getLookupTableid());

recList.setSession(authUser.getSession());

recList.setResultDefinition(rd);

recList.setSearch(search);

recList.execute();

//Record result set

rrs = recList.getRecords();

//record array is set with the lookup table records and get the recordIDs

recs= rrs.getRecords();

//while you create or modify a record you need pass lookupFieldid in maintable and the record IDn the record

record.setFieldValue(cfid<i>.getId(),new LookupValue(recs[1].getId()));

This work for me in create and i hope there is littel difference between create and modify.

Get back for help,

Vijay

namrata_d
Active Participant
0 Kudos

Hi Ninad,

The below code can be used for fetching data from lookup Table. The tableid is the id for lookup table and fieldid is the id for field which you want to display.

ResultDefinition rsd = new ResultDefinition(new TableId(tableID));

fsd.addSelectField(new FieldId(FieldId));

com.sap.mdm.search.Search srch = new com.sap.mdm.search.Search(new TableId(tableID));

RetrieveLimitedRecordsCommand limited_commands = new RetrieveLimitedRecordsCommand(connections);

limited_commands.setResultDefinition(rsd);

limited_commands.setSearch(srch);

limited_commands.setSession(sessionID);

try {

limited_commands.execute();

} catch (Exception e1) {

// TODO Auto-generated catch block

System.out.println(e1.toString());

}

RecordResultSet rs = limited_commands.getRecords();

if(rs.getCount()>0)

{

lookUp_data = new String[rs.getCount()];

for(int i =0;i<rs.getCount() ; i++)

{

lookUp_data<i> = rs.getRecord(i).getFieldValue(new FieldId(FieldId)).toString();

}

}

I hope the code solves your problem.

Thanks

Namrata

Answers (0)