on 10-26-2007 2:07 PM
Hi,
i'm newbbie,
i want to know hoe to retrive all records of a main table, Including lookup hierarchy and lookup qualified flat field, with java API.
Can someone posting some sample code ?
Thanks and Regards.
i'm using MDM4J5.5 sp5.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrea,,
I hope the following code might help u in ur problem..
Kindly revert back if any point is not clear in the code.
public void fetchDatafromMainTable(ConnectionPool connections , String sessionId)
{
//Getting the Record id of the Material number to be modified with the new Qualified
ResultDefinition rsd = new ResultDefinition(new TableId(1));//Main Table
rsd.addSelectField(new FieldId(<FieldID of type qualified in main tabel>);
rsd.addSelectField(new FieldId(<FieldId of Text type));
rsd.addSelectField(new FieldId(<FieldId of LookUp Flat type>));
StringValue [] val = new StringValue[1];
val[0] = new StringValue("8393);//Material or Partner ID on the basis of which the values are to be fetched
RetrieveRecordsByValueCommand val_command = new RetrieveRecordsByValueCommand(connections);
val_command.setSession(sessionId);
val_command.setResultDefinition(rsd);
val_command.setFieldId(new FieldId(Schema.PRODUCTS_FIELDID.MATERIAL_ID));
val_command.setFieldValues(val);
try
{
val_command.execute();
}
catch(Exception e)
{
System.out.println(e.toString());
}
RecordResultSet result_set = val_command.getRecords();
MdmValue value = null;
if(result_set.getCount()>0)
{
for(int i = 0 ; i < result_set.getCount() ; i ++)
{
System.out.println(result_set.getRecord(i).getFieldValue(new FieldId(<FieldID of Text type >)));//this fieldID should be added in ResultDefinition before
System.out.println(result_set.getRecord(i).getFieldValue(new FieldId(<FieldID of LookUP Flat type >)));//this fieldID should be added in ResultDefinition before,,,,it will return RecordID and from there again execute the RetrieveRecordsByID command and fetch the value
value = result_set.getRecord(i).getFieldValue(new FieldId(Schema.PRODUCTS_FIELDID.REQUEST_DETAILS));//Qualifier fieldID....This will give you all the YES qualifiers
//For fetching No Qualifier of this field
QualifiedLookupValue qLookupVal = new QualifiedLookupValue();
QualifiedLinkValue qlinkVal = null;
//retriving the qualified lookup value of the qualified field
qLookupVal = (QualifiedLookupValue) value;
//RecordResultSet For Qualified Table Record
RecordResultSet QTableResultSet = null;
//array list to hold qualified table records
ArrayList qTableRList = new ArrayList();
// System.out.println("The Number Of Qualified Links with "" is "qLookupVal.getQualifiedLinks().length);
for(int n = 0 ; n < qLookupVal.getQualifiedLinks().length ; n++)
{
RecordId [] rec_id_arr = new RecordId[1];
rec_id_arr[0] = qLookupVal.getQualifiedLink(n).getLookupId();
ResultDefinition rsd1 = new ResultDefinition(new TableId(<TableID of Qualified table>));//the qualified table from which NO qualifiers are to be retrieved
rsd1.addSelectField(new FieldId("F541_62555"));//Requester Name - No Qualifier
RetrieveRecordsByIdCommand records_by_id = new RetrieveRecordsByIdCommand(connections);
records_by_id.setIds(rec_id_arr);
records_by_id.setSession(sessionId);
records_by_id.setResultDefinition(rsd1);
try {
records_by_id.execute();
} catch (CommandException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
RecordResultSet rs = records_by_id.getRecords();
for(int p = 0 ; p < rs.getCount() ; p++)
{
// System.out.println(rs.getRecord(p).getFieldValue(new FieldId("F541_62555")).toString());//Fetching the No Qualifier
}
}
}
}
Thanking you
Namrata Dixit
Hi Andrea,
To insert a record in lookup hierarchy you need the RecordID of the value to be inserted.
I hope the following code helps you in achieving your problem
For the Qualified value the process goes as:-
//Creating record in Qualifed table Request Details
//Adding No Qualifiers
Record qualified_record = RecordFactory.createEmptyRecord(new TableId("T108"));//TableID of Qualified table
try {
qualified_record.setFieldValue(new FieldId(<FieldID of No Qualifier>), new StringValue("xyz"));//Adding Requester name - No Qualifier
} catch (IllegalArgumentException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (MdmValueTypeException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
//Creating Record in Qualified Table - Request Details
CreateRecordCommand create_command = new CreateRecordCommand(connections);
create_command.setSession(sessionId);
create_command.setRecord(qualified_record);
try
{
create_command.execute();
}
catch(Exception e)
{
System.out.println(e.toString());
}
RecordId record_id = create_command.getRecord().getId();
//Adding the new record to Qualifed Lookup value and setting the Yes Qualifiers
QualifiedLookupValue lookup_value = new QualifiedLookupValue();
int link = lookup_value.createQualifiedLink(new QualifiedLinkValue(record_id));
//Adding Yes Qualifiers
lookup_value.setQualifierFieldValue(0 , new FieldId(<FieldID of yes Qualifier>) , new StringValue("namrata@wipro.com"));//Setting the Yes Qualifier value
And finally in CreateEmptyRecord command set it as
empty_record.setFieldValue(new FieldId(<FieldID of field in Main table-Qualified type), new QualifiedLookupValue(lookup_value));
Thanks
Namrata
Hi Namrata,
I do it like this:
QualifiedLinkArray qla = new QualifiedLinkArray();
QualifiedLink ql = new QualifiedLink();
ql.SetLookupID(lookupID);
for (int x = 0; x < qualiferFields.GetCount(); x++) {
ql.GetQualifiers().Add(qualiferFields.GetAt(x));
}
qla.Add(ql);
int changeStamp = -1;
try {
connection = ConnectionManager.getConnection();
CatalogData catalog = ConnectionManager.getCatalogData(connection);
changeStamp = getChangeStamp(catalog, mainTableName, mainRID);
catalog.AddQualifiedLinks(
mainTableName,
qualifiedFieldName,
mainRID,
qla,
changeStamp);
} catch (Exception ex) {
throw new Exception(ex.toString() );
}
But i get ModifyQualifiedLinks error .
Any suggest ?
Thanks
Andrea
Hi Andrea,
I guess previously you were trying out the code in JAVA API 2.
But now it seems you are trying to add a New Qualified link through JAVA API 1.
For creating a qualified link in Main table the code snippet that you have written seems to be OK.
Just check if you have added the a2iField to qualified link properly. for text values , the Value object should contain directly the value and for LookUP flat Value object should contain the RecordID of the value selected.
Thanks
Namrata
If you need a code snippet for adding a qualified table in Main table through JAVA API 1 do let me know.
Thanks,
i set the A2iFields like this:
A2iFields fields = new A2iFields();
A2iField field = new A2iField Schema.Gruppi_Merce.CLASSIFICAZIONE_MERCEOLOGICA);
fields.Add(field);
Where Gruppi_Merce is Main Table and CLASSIFICAZIONE_MERCEOLOGICA is lookup field to Hierarchy table.
Thanks end Regards.
Andrea
Hi Andrea,
In A2iField you need to create its object like this:-
A2iField sys = new A2iField(Schema.SEGMENT,
new Value(req_details.getSegment_RecID())); //Segment is a hierarchy and in Value object we are passing the ReordID of the node seleted by the user.
qualifiedLink.GetQualifiers().Add(sys);
Hi Namrata,
I do it, but i get an error :
java.lang.RuntimeException: Field classificazione_merceologica_lk doesn't exist in table classificazione_merceologica
classificazione_merceologica_lk is a lookup field in the main,
classificazione_merceologica is a Hierarchy table.
Any idea.
Thanks
Andrea
Hi Andrea,
Are you trying to create a record in Hierarchy table or in Main table with the Specified RecordID??
According to this error it seems that you are adding A2ifield object to Hierarchy table and not to Main table.
IF the lookup field for hierarchy is in Main table:--
then create A2ifield object and add it to A2ifields Object.
If the lookup field for hierarchy is in Qualified table then do it as i have mentioned in last post.
Just confirm once again where are you adding your A2ifield object to??
thanks
Namrata
Hi Namrata,
i create record in the main table like this:
recordID = catalog.AddRecord(aTable, fieldsA2i, 1, 1);
And retrieve the recordId
I want to add a lookup field to hierarchy in the main.
The A2ifield object contains the name of the lookup field to hierarchy in the main,
and the value is recordId of the Hierarchy record.
This is the way i do, but dosen't work.
Thanks
Andrea
Hi Namrata,
I catch the record id in the hierarchy table in this way.....
A2iStringArray values = new A2iStringArray();
values.Add(value);
ResultSetDefinition rsd = new ResultSetDefinition(table);
rsd.AddField(displayField);
A2iResultSet rs = null;
rs = catalog.GetRecordsByValue(values, rsd, displayField);
if (rs.GetRecordCount() > 0) {
returnVal = rs.GetRecordIDAt(0);
}
It's OK?
Thanks
Andrea
Hi Namrata,
The lookup hierarchy field is in a main table.
Than i don't use qualified to add it to main, but i must use A2iFields ....it's correct?
If yes, i must fill the A2iFields with the value of record of the hierarchy ? How ?
But i don't add the recordId to add to main instead of A2iFields ?
Sorry i'm a bit confused.
Thanks
Andrea
Hi Andrea,
You lookUp hierarchy field is in Main table so you need not use Qualified links.
For adding it in Main table:-
A2iFields fld_arr_main = new A2iFields();
A2iField hierarchy_field = new A2iField("<lookup field in main table>",new Value(<RecordID of the value selected>));
fld_arr_main.Add(hierarchy_field);
try{
rec_id = cd.AddRecord(Main tableCode,fld_arr,0,0);
}catch(Exception ex){
rec_id = -1;
error = ex.toString();
}
Hi Andrea,
Which JAVA API are you intending to use???
Accordingly i can provide you with the sample code.
Thanks
Namrata Dixit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
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.