cancel
Showing results for 
Search instead for 
Did you mean: 

Get Records in a named search

Former Member
0 Kudos

Hello,

I have a namedsearch say plant_xxx.

Can we read the records in this namedsearch using mdm java api's.

If so, please let me know the code snippet to get the records in this namedsearch.

Thanks

MLS

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Laxmi,

Yes, we can read records in the named serach. We have to use NamedSearchSearchDimension & PickListSerachConstarint to read records in particular named search, all repository named searches will be stored in Named Serch table, so we need to get record id of particular named search (ex Plant_xx) and pass MDM value to PickListSearchConstarint.

Plz see the below code

TableSchema tableSchema = schema.getTableSchema("main table Code"); // Ex vendor,product etc....

Search objSearch = new Search(tableSchema.getTable().getId());

RecordId recordId = new RecordId("R1"); // Record id of Named Search (plant_xxx) in Named serach table

SearchDimension searchDimension = new NamedSearchSearchDimension();

MdmValue requestValue = new LookupValue(recordId);

MdmValue[] values = ;

SearchConstraint searchConstraint = new PickListSearchConstraint(values);

SearchParameter searchParameter = new SearchParameter(searchDimension, searchConstraint);

objSearch.addSearchItem(searchParameter);

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

resultDef.setSelectFields(tableSchema.getFieldIds());

RetrieveLimitedRecordsCommand limitingCommand;

try {

limitingCommand = new RetrieveLimitedRecordsCommand(context);

limitingCommand.setResultDefinition(resultDef);

limitingCommand.setSearch(objSearch);

limitingCommand.execute();

} catch (SessionException e) {

} catch (ConnectionException e) {

} catch (CommandException e) {

throw new VendorException(e);

}

if(limitingCommand.getRecords()!= null){

System.out.println("Number of records:"+limitingCommand.getRecords().getCount());

Record [] records = limitingCommand.getRecords().getRecords();

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

System.out.println("Record ["i"]: Value "+records<i>.getDisplayValue());

}

}else{

System.out.println("no records:");

}

Hope it helps.......

Cheers,

Veeru