cancel
Showing results for 
Search instead for 
Did you mean: 

Update field of type loookup table

Former Member
0 Kudos

Hi,

Am working to update a field 'X' of type lookup table[flat] in the database.

Another method of mine returns the value of field 'X' as a string.Now i need to set this value of type string and update the lookup table.

Please find my code below :

String X = getData();

MdmValue m1 = new StringValue(X );

LookupValue m2 = (LookupValue)m1 ;

RecordId recordId = m2.getLookupId();

record.setFieldVlue(FieldId,new LookupValue(recordId));

But this throws a class cast exception.Can someone let me know how to change this string value 'X' to type lookup table[flat]?

How do i update the value of field 'X which is of type lookup flat in my MDM repository? By typecasting or is there someother way of doing the same?

Thanks

Rekha

Accepted Solutions (0)

Answers (3)

Answers (3)

nitin_mahajan2
Contributor
0 Kudos

Lookup field does not store the actual value of the lookup field maintained on main table. The field value is maintained on lookup table and the lookup field contains only the reference which is Record Id of the lookup table.

The logic of your implementation should go like this:

When you read the lookup table at the first place, get fields that you want to update and also the Record Id of the record of lookup table.

Now you want to update the lookup table value and also set it to another record.

First: Update the lookup table record using the modify record command. You already have the lookup record Id.

Get the lookup record from the lookup table.

Use the following code:


String abc = "abc" ;
MDMValue val = new MDMValue( abc ) ;
lookupRecord.setFieldValue(fieldId, val) ;

Use the modifyrecord command to modify the lookup record.

Now you can get the record Id either from this command or you will have the record Id of the record when you first retrieved it.

If the mapping of the lookup table is already there on the main table, no need to do the second step.

Second: Set the lookup Record Id as the field value of the lookup field in the main table and update the main table record.


LookupValue lookupVal = new LookupValue( lookupRecord.getId( )  )
mainRecord.setFieldValue( fieldId, lookupVal ) ;

use the modify command to update the main table.

If you need the detail code, let me know. but it would be good if you try it out.

Regards and good luck

Nitin

Edited by: Nitin Mahajan on Jun 3, 2009 11:28 PM

Edited by: Nitin Mahajan on Jun 3, 2009 11:32 PM

Edited by: Nitin Mahajan on Jun 3, 2009 11:37 PM

Former Member
0 Kudos

Hi Rekha,

Try the below code

String X = getData();

MdmValue m1 = new StringValue(X );

record.setFieldVlue(FieldId,m1);

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi,

To update a field of type lookup flat in a table first you have to get the lookup value from lookup table.

1. Get the record id from the look up table (Using RetrieveLimitedRecordsCommand).

2. Construct LookupValue object.

LookupValue lookupval = new LookupValue(recordid);

3. set this lookup value to the record.

record.setFieldValue(fieldid,lookupval);

Plese let me know if you need any thing else.

Thanks,

Sreenivasulu.

Former Member
0 Kudos

Hi,

But this will pass the lookuprecord id.How will my value be set exactly?Am getting the value of 'X' as a string from some method.Please let me know.

Thanks,

Rekha

Former Member
0 Kudos

Hi,

Can you please tell me the Lookup table structure.

Former Member
0 Kudos

Hi,

I have to update a field X of datatype lookup table[flat].This field has 4 different values.

Currently after doing some validation am getting the field as a String.How do i convert this?

Hope you can understand.

Thanks,

Rekha