cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve data foe a Flat Look Up Field

Former Member
0 Kudos

hi Everybody,

I am Looking for help to fetch Flat look Up Field Values.

I am trying to find the value of a field ( which is of type Flat look Up) for a particular record in the main table. I'm able to fetch TEXT ( direct ) fields from the table but seems there is some specific method to get the value for look up field.

While trying to get the value of this field, I'm getting RecordID of the same. With which I can certainly go n search the lookup table. But it doesnt look efficient to me.

Even a small hint would will be really helpful.

Regards

Namrta Mahajan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

<b>Record.findLookupRecords(FieldId)</b> - Will help you to fetch the lookup records associated with main table..

Former Member
0 Kudos

Hi Gurushant,

Yes i am fetching the lookUP record,

And storing them in the Record Array.When I Print the length of the record or the value of the record its giving me null pointer exception.

Whereas in Data Manager the Data is there

Former Member
0 Kudos

Hi Gurushant,

Can you please send me the some sample Code regarding this,

If you have tried this.

Former Member
0 Kudos

Hi Namrta,

Please find the sample to retrieve the Look up Field values:

Hope you would be retrieving the TEXT data using Record.getFieldValue(FieldId) API.

Consider the following Exampple:

<b>Table : Person

Field Name | Field Code| Type

Name | NAME | TEXT

Address | ADDR | Lookup[Flat]

Table : Address

Address Id | ADDR_ID | TEXT

Address Line1 | ADDR_LN_1| text</b> (Could be a display field)

Let's say you are intrested in looking for Address Line1 from table Person.

for retrieving the value of the name you would be using:

<b>FieldId nameFieldId = repositorySchema.getFieldId('Person','NAME').getId();

FieldId addressFieldId = repositorySchema.getFieldId('Person','ADDR').getId();

FieldId addressLine1FieldId = repositorySchema.getFieldId('Address','ADDR_LN_1').getId();

String name = Record.getFieldValue(nameFieldId).toString();</b>

For Flat Lookup field Value :

<b>MdmValue mdmValue = Record.getFieldValue(addressFieldId);</b>

Check for the following condition (This block would enter if and only if the field contains value!)

<b>String addressLine1 = null;

if(mdmValue.getType() != MdmValue.Type.NULL && mdmValue.getType() == MdmValue.Type.LOOKUP){

Record[] addressRecords = Record.findLookupRecords(addressFieldId);

if(null != addressRecords){

addressLine1 = addressRecords[0].getFieldValue(addressLine1FieldId);

}

}</b>

Code at this line must have addressLine1 populated with lookupvalue.

Hope it helps.. Sorry for delay in response...........

Regards,

Guru

Message was edited by:

Gurushant Hanchinal

Former Member
0 Kudos

Thanks Gurushant,

But i am still getting null for the Line Code:

Record[] addressRecords = Record.findLookupRecords(addressFieldId);

But actually in data managaer the data is there.

Regards

Namrata

Answers (3)

Answers (3)

Former Member
0 Kudos

Found the solution , But thats very long way, still trying to find some other way for it.

Former Member
0 Kudos

Hi Namrata,

I am working on the same thing for SPO6.

Please can you let me know the optimum solution around it?

Thanks,

Sandeep

Former Member
0 Kudos

Hi,

Which API are you using?

Walter

Former Member
0 Kudos

I am using Java API 2

Former Member
0 Kudos

Hi Namrata ,

It seems page 110 of console manager will help you in 'display fields' of lookup fields .

Hope it helps ,

- An

Former Member
0 Kudos

Hello:

Actually the way you are doing it is the right way. In the main table, get the lookup field ID. With this ID, go to the lookup table and retrieve the record.

it's quite efficient, because in this way you can get all the fields of the lookup table, which are not loaded when you get only the main table

I hope this helps

Alejandro

Former Member
0 Kudos

Hi An,

Can you please tell me about which Doc of page 110 you are referring.

or if you have them Can you please send me

Regards Namrta.