on 04-03-2008 10:59 AM
Hi,
I have created a progam to update the records in main table.
But, in the case of Lookup fields, I have to pass the Lookup table's record id into the main table.
In order to achieve this, I have to find out the Lookup Table id.
Can any one , please let me know how to retrieve the lookup table record id, by giving Main table lookup field id as the input.
Thanks,
Priya.
Hi Priya,
I am attaching the sample code.Sure this will help you
GetRepositorySchemaCommand getRepSchemaCmd = new GetRepositorySchemaCommand(connection);
getRepSchemaCmd.setSession(sessionId);
try
{
getRepSchemaCmd.execute();
}
catch(CommandException e)
{
System.out.println(e.getLocalizedMessage());
}
RepositorySchema repSchema = getRepSchemaCmd.getRepositorySchema();
TableId lookupTableId = new TableId("Countries"); //Countries is the code of the lookup table
ResultDefinition rd = new ResultDefinition(lookupTableId);
//Select all records
Search search = new com.sap.mdm.search.Search(lookupTableId);
//Get fields
GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connection);
getFieldListCommand.setSession(sessionCommand.getUserSession());
getFieldListCommand.setTableId(lookupTableId);
try
{
getFieldListCommand.execute();
}
catch (CommandException e)
{
System.out.println(e);
}
FieldProperties[] lookupFields = getFieldListCommand.getFields();
//Add fields to records to retrieve
rd.addSelectField(repSchema.getFieldId("Countries","Name"));
rd.addSelectField(repSchema.getFieldId("Countries","Code"));
//Retrieve the records
RetrieveLimitedRecordsCommand retriveLimRecCommand = new RetrieveLimitedRecordsCommand(connection);
retriveLimRecCommand.setSession(sessionId);
retriveLimRecCommand.setResultDefinition(rd);
retriveLimRecCommand.setSearch(search);
try
{ retriveLimRecCommand.execute();
}
catch (CommandException e)
{
e.printStackTrace();
}
System.out.println("Record count is " + retriveLimRecCommand.getRecords().getCount()+"\n");
Record[] records = retriveLimRecCommand.getRecords().getRecords();
System.out.print(records[3].getFieldValue(repSchema.getFieldId("Countries","Code"))+" ");
I am using System.out.print you can pass this value while modifying the main table field.
Hope this will help you...
Please let me know if any further help is required.
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,
Thanks for the reply....
In your case, you know the Lookup Table Name(Code), so, you have retrieved the table id.
But my case is like, I know, there is a field in Main table of type Lookup Flat.
I know the field Id of that field in the main table.
Now, with this information how will I retrieve, which is the Lookup table that is liked to the main table field., ie the name of the lookup table, linked to the main table field.
Thanks,
Priya.
HI,
I have tried this also, but it did not work
int intfieldId = fieldProp[t].getId().getIdValue();
LookupFieldProperties lookupProp = new LookupFieldProperties(intfieldId);
I got an error as
Exception in thread "main" java.lang.UnsupportedOperationException
at com.sap.mdm.schema.fields.LookupFieldProperties.<init>(LookupFieldProperties.java:22)
at programs.ModifyRecord.main(ModifyRecord.java:102)
Thanks,
Priya.
Hi Priya,
int intfieldId = fieldProp[t].getId().getIdValue();
LookupFieldProperties lookupProp = new LookupFieldProperties(intfieldId);
LookupFieldProperties (int type)
parameter should specify the type of lookup like Flat,Qualified,Hierarchy etc not the field id.
So instead of passing fieldid try passing field type.
E.g.LookupFieldProperties lfp=new LookupFieldProperties(fieldProp[t].getType())
Regards,
Jitesh Talreja
Hi,
You can get this through MAM Java API's itself, MDM4J is not required.
LookupFieldProperties lookupFieldSer = (LookupFieldProperties) lookupFieldProp;
Table Id lookupTable = lookupFieldSer.getLookupTableId();
lookupFieldProp -
> Lookup Field Properties in Main Table.
lookupTable -
> Lookup table id.
Thanks,
Priya.
Hi Priya,
I think, by applying a drill down search in Data Manager on the look up table field, u ll be able to get the look up table record id.
Thanks and Regards,
shreya.
Edited by: Shreya Landge on Apr 3, 2008 12:08 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think you did not understand me.
I forgot to tell you, I am using Java API's to do this.
So, while using Java API, every Record, every Table and every field is associated with with an id.
so now, my concern, is to find the lookup table name or atleast the lookup table id, when main table field id is given as the input.
Thanks,
Priya.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.