cancel
Showing results for 
Search instead for 
Did you mean: 

Search Using Lookup Field using Java API

Former Member
0 Kudos

Hi,

Is it possible to make a search based on the Lookup Filed, present in the main table.

I am using the following Search Parameter

FieldSearchDimension fsdMaintableType = new FieldSearchDimension(new FieldId(fieldName.getId())); ---> Lookup Field ID

TextSearchConstraint tscMainTypeRoot = new TextSearchConstraint( new LookupValue(resSetLookup[r].getId()).toString(), TextSearchConstraint.CONTAINS);

new LookupValue(resSetLookup[r].getId()).toString() -- Lookup value Record ID

I am assing both these values to search Class

Search seSearchMainRoot = new Search(new TableId(tabProp.getId())); -


> Main Table ID.

seSearchMainRoot.addSearchItem(fsdMaintableType, tscMainTypeRoot);

When I use RetrieveLimitedRecordsCommand -- i get the array as Null in the result set.

Could anybody please let me know, whether, search through Lookup field in Main table is possible??

Thanks,

Priya.

Accepted Solutions (0)

Answers (3)

Answers (3)

Greg_Austin
Active Participant
0 Kudos

Assuming you are passing the RecordId of the Lookup table as Jitesh said you could also use a PickListSearchConstraint instead of the TextSearchConstraint. The PickListSearchConstraint takes and MdmValue[] so pass the LookupValue you are already creating in to the constructor as an array and you should be able to get the search to return the results you want.

-Greg

Former Member
0 Kudos

Hi,

Thanks for the reply.

By using, PickListSearchConstraint the isue is solved, now i am able to search by Lookup field in the Main table.

Thanks for your iputs.

Priya.

Former Member
0 Kudos

Hi Priya,

Your understanding is proper.

Try fetching the lookup record id from the Lookup table instead of taking the reference from the main table lookup field.

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Priya,

I am attaching the sample code below whose purpose is to Search TMData where registration status is "Registered" and target market is "Germany" also retrieve filtered lookup values for information provider and GDSN registration status.

Hope it will help you.

-


Global Variables----


static RetrieveLimitedRecordsCompoundCommand rlreCommand = null;

static FieldId mainFid3;

static FieldId mainFid4;

static FieldSearchDimension sd5;

-


static void lookUpSearch() throws Exception

{

RecordResultSet rrs;

TableId lookTableId;

try

{

TableId [] tid = MetadataManager.getInstance().getRepositorySchema(sessionContext).getTableIds();

TableId mainTableId = new TableId(1);

lookTableId = new TableId(1);

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

{

if(MetadataManager.getInstance().getRepositorySchema (sessionContext).getTableCode(tid<i>).equalsIgnoreCase("TMData"))

{

mainTableId = tid<i>;

}

else if(MetadataManager.getInstance().getRepositorySchema(sessionContext).getTableCode(tid<i>).equalsIgnoreCase("Parties"))

{

lookTableId = tid<i>;

}

}

FieldProperties [] mainFp = MetadataManager.getInstance().getRepositorySchema(sessionContext).getFields(mainTableId);

FieldId mainFid = mainFp[0].getId();

FieldId mainFid2 = mainFp[0].getId();

System.out.println("mainFp[0].getId = "+mainFid);

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

{

if(mainFp<i>.getCode().equalsIgnoreCase("RegistrationStatus"))

{

mainFid = mainFp<i>.getId();

System.out.println("mainFid = "+mainFid);

}

else if (mainFp<i>.getCode().equalsIgnoreCase("TargetMarket"))

{

mainFid2 = mainFp<i>.getId();

System.out.println("mainFid2 = "+mainFid2);

}

else if (mainFp<i>.getCode().equalsIgnoreCase("InformationProvider"))

{

mainFid3 = mainFp<i>.getId();

System.out.println("mainFid2 = "+mainFid2);

}

else if (mainFp<i>.getCode().equalsIgnoreCase("GDSNRegistrationStatus"))

{

mainFid4 = mainFp<i>.getId();

System.out.println("mainFid4 = "+mainFid4);

}

}

Search sch = new Search(mainTableId);

FieldSearchDimension sd = new FieldSearchDimension(mainFid);

TextSearchConstraint sc = new TextSearchConstraint("Registered",TextSearchConstraint.EQUALS);

sch.addSearchItem(sd,sc);

FieldSearchDimension sd2 = new FieldSearchDimension(mainFid2);

TextSearchConstraint sc2 = new TextSearchConstraint("Germany",TextSearchConstraint.EQUALS);

sch.addSearchItem(sd2,sc2);

rlreCommand.setSearch(sch);

// create the search dimensions for retrieving fileter values for information provider and GDSN registration status.

sd5 = new FieldSearchDimension(mainFid3);

SearchDimension [] sdarray = {sd5, new FieldSearchDimension(mainFid4)};

rlreCommand.setSearchDimensions(sdarray);

getResultSet(mainFp);

}

catch(Exception e)

{

throw e;

}

}

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi,

Thanks for the reply.

The problemm that I am facing is, I wanted to retrieve main table record, when a lookup table field is present in the search parameter.

As you know, the lookup table record id is stored, in the Main table Lookup field.

So, whast i have done is I am retrieving the lookup record id and passing it in the TextSearchDimension class, but i am getting null value.

In you example, you have retieved the main table records, with a text field in search parameter, along with the lookup field value. -- Is my understanding correct.

Please let know.

Thanks,

Priya.