on 09-20-2007 2:48 PM
Hi All,
I am trying to update existing record but I am not getting how to change the lookup field so can any one tell me how we can do this.
Thanks
Ninad
I assume you are talking about changing the value of a field that is of type Lookup [Flat]? If so when you are setting the fields new value you give a LookupValue type. The constructor of LookupValue takes a RecordId of the table the field looks up to. You can get the correct RecordId by doing a search on the lookup table and using the .getId() method on the correct Record.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ninad,
Use this commands to fetch all data from Lookup table.
You need to fetch
// Retrive all records from Look up table
RetrieveLimitedRecordsCommand recList = new RetrieveLimitedRecordsCommand(connection);
// Get the Look up field props by type casting to List of fields props of maintable
LookupFieldProperties lf = (LookupFieldProperties) cfid<i>;
rd = new ResultDefinition(lf<i>.getLookupTableid());
rd.setSelectFields(fid);
Search search = new Search(lf<i>.getLookupTableid());
recList.setSession(authUser.getSession());
recList.setResultDefinition(rd);
recList.setSearch(search);
recList.execute();
//Record result set
rrs = recList.getRecords();
//record array is set with the lookup table records and get the recordIDs
recs= rrs.getRecords();
//while you create or modify a record you need pass lookupFieldid in maintable and the record IDn the record
record.setFieldValue(cfid<i>.getId(),new LookupValue(recs[1].getId()));
This work for me in create and i hope there is littel difference between create and modify.
Get back for help,
Vijay
Hi Ninad,
The below code can be used for fetching data from lookup Table. The tableid is the id for lookup table and fieldid is the id for field which you want to display.
ResultDefinition rsd = new ResultDefinition(new TableId(tableID));
fsd.addSelectField(new FieldId(FieldId));
com.sap.mdm.search.Search srch = new com.sap.mdm.search.Search(new TableId(tableID));
RetrieveLimitedRecordsCommand limited_commands = new RetrieveLimitedRecordsCommand(connections);
limited_commands.setResultDefinition(rsd);
limited_commands.setSearch(srch);
limited_commands.setSession(sessionID);
try {
limited_commands.execute();
} catch (Exception e1) {
// TODO Auto-generated catch block
System.out.println(e1.toString());
}
RecordResultSet rs = limited_commands.getRecords();
if(rs.getCount()>0)
{
lookUp_data = new String[rs.getCount()];
for(int i =0;i<rs.getCount() ; i++)
{
lookUp_data<i> = rs.getRecord(i).getFieldValue(new FieldId(FieldId)).toString();
}
}
I hope the code solves your problem.
Thanks
Namrata
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.