on 06-01-2009 8:34 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rekha,
Try the below code
String X = getData();
MdmValue m1 = new StringValue(X );
record.setFieldVlue(FieldId,m1);
Regards,
Jitesh Talreja
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.