cancel
Showing results for 
Search instead for 
Did you mean: 

get All record of Main Table

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

i'm using MDM4J5.5 sp5.

Thanks

namrata_d
Active Participant
0 Kudos

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

Former Member
0 Kudos

Wow !!!

All works.

Another question.

If i must insert a record in a lookup hierarchy or in lookup qualified flat table,

how can i reference this record in the main Table ?

Thanks a lot !

Andrea

namrata_d
Active Participant
0 Kudos

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

Former Member
0 Kudos

Sorry i don't understand very well.

If i add a record to the main table, in the field (of main) that reference lookup hirarchy table i must insert the id of the record in the hierarcy ?

I'm a bit confused.

Thanks for the support.

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Yes if you want to insert a value into Main table which is of Hierarchy type ,,u have to pass RecordID of that value while creating or updating that record.

Please award points if found helpful..

Thanks

Namrata dixit

Former Member
0 Kudos

The logic is OK, but when i insert a record in the main table, i insert the Id (Casted to String) in the relative hierarchy field they return a2i.core.StringException.

Any idea.

Thanks

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

I think the place where you might be going wrong is while inserting into Main table you need to pass it as LookUpValue and in LookUpValue pass the recordID of that value selected from hierarcchy.

Thanks

Namrata Dixit

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

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.

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

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);

Former Member
0 Kudos

Hi Namrata,

I don't understand

Segment is a hierarchy lookup field from the main?

The record id to set as value, is record id of the record in the hierarchy or record in the main?

Thanks

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Yes the RecordID is of the record in the Segment hierarchy table.

Thanks

Namrata

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

Hi Andrea,

You are adding a record in Main table so the third and four parameters in your case should be 0 ,0.

i.e

recordID = catalog.AddRecord(aTable, fieldsA2i, 0, 0);

these are used only when you trying to create a record in Hierarchal table.

Thanks

Namrata

Former Member
0 Kudos

Thanks,

I correct the insert in the main table, but i got the same error.

Regards

Andrea

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

Hi Andrea,

you function for retrieving RecordID is fine.

Are you getting the same error as before??

Thanks

Namrata

Former Member
0 Kudos

Hi Namrata,

Yes I got the same error.

Do you have a sample code to do this?

Thanks

Andrea

Former Member
0 Kudos

Hi Namrata,

I have a question.

I have a lookup hierarchy field, non lookup qualified field, why i must use QualifiedLink ?

Thanks

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Sorry i didnt get you question.

If the LookUp hierarchy field is in Main table add it to A2iFields Object and if the LookUp hierarchy field is in Qualified table then add it as qualified_link.getQualifiers.add(<your A2iField object>)

Thanks

Namrata

Former Member
0 Kudos

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

namrata_d
Active Participant
0 Kudos

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();

}

Former Member
0 Kudos

Hi Namrata,

Thanks for your help,

i do it in your way and i got StringException when i addRecord,

the recordId that i added is id of child record, maybe i must add a recordId of root node?

Thanks

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Normally this StringException also comes when the field code is wrong.Inserting a RecordID of a child node should doesnt give any prob.

Just chk the fielcode once again.

Thanks

Namrata

Former Member
0 Kudos

Hi Namrata,

I found on the repository schema that the fildcode it's the same, and the type of value is HierMultiSubTableField.

any idea?

Thanks

Andrea

Former Member
0 Kudos

Hi Namrata,

i pass the recordId as int type....it's correct?

Thanks

Andrea

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Passing the RecordID as int type is correct.

Thanks

Namrata

namrata_d
Active Participant
0 Kudos

Hi Andrea,

Which JAVA API are you intending to use???

Accordingly i can provide you with the sample code.

Thanks

Namrata Dixit