cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to retrieve and insert the value to Home_country filed in MDM

former_member192283
Participant
0 Kudos

Hi All,

I am new to the JAVA API,

I have creted one application in webdynpro using the JAVA API. I am able to search the data based on "Firstname" "Lastname" and "Email address".

I need to basically two functionalities

1) Search

2) Insertion of new records

*1) Search*__

But searching based on the Country is not able to do it.

we have two tables .

1) Country table> Contains all the list of the country codes and County name.

2) People table > Contains the country filed. So for this filed lookup table is country. also this country filed is drop down not have opton edit in the MDM.

I am sending the following used for searching the records based on the First Name and country.

But based on the first name it is working fine but Country it is giving some code like "R100" "R12". It is not givng the actual name of the country.

FieldSearchDimension sd1 = new FieldSearchDimension(fields[2].getId());

TextSearchConstraint sc1 = new TextSearchConstraint(First_Name,TextSearchConstraint.EQUALS);

sch.addSearchItem(sd1,sc1);

FieldSearchDimension sd4 = new FieldSearchDimension(fields[9].getId());

TextSearchConstraint sc4 = new TextSearchConstraint(Home_Country,TextSearchConstraint.EQUALS);

// TextSearchConstraint sc4 = new TextSearchConstraint("IN",TextSearchConstraint.EQUALS);

sch.addSearchItem(sd4,sc4);

cmd = new RetrieveLimitedRecordsCommand(connections);

cmd.setResultDefinition(rdPeople);

cmd.setSearch(sch);

cmd.setSession(sessionId);

try

{

cmd.execute();

}

catch(CommandException e)

{

e.printStackTrace();

}

recs = cmd.getRecords();

wdContext.nodeResult_Table().invalidate();

//retreiving the Data from the resultset

if(recs.getCount()!=0)

{

for(int i=0;i<recs.getCount();i++)

{

//First Name

IResult_TableElement resEle=wdContext.nodeResult_Table().createResult_TableElement();

if(!(recs.getRecord(i).getFieldValue(fields[0].getId()).isNull()))

{

//wdComponentAPI.getMessageManager().reportSuccess("Network Id-->"+recs.getRecord(i).getFieldValue(fields[0].getId()).toString());

resEle.setNetwork_ID(recs.getRecord(i).getFieldValue(fields[0].getId()).toString());

}

//Country

if(!(recs.getRecord(i).getFieldValue(fields[9].getId()).isNull()))

{

resEle.setDisplay_Name(recs.getRecord(i).getFieldValue(fields[9].getId()).toString());

}

wdContext.nodeResult_Table().addElement(i,resEle);

}

By the above field is not giving the respective country name is avilable. it is giving some value"R100" rather giving of India.

_ 2) For creating the record in the "people" table._

I am able to insert the data all the information "firstname" "Last name", "email" except "Country" entered by the user by using the following code.

//Insert

First_Name=wdContext.currentPersonal_DetailsElement().getAttributeAsText("First_Name");

Last_Name=wdContext.currentPersonal_DetailsElement().getAttributeAsText("Last_Name");

Middle_Name_or_Initial=wdContext.currentPersonal_DetailsElement().getAttributeAsText("Middle_Name_or_Initial");

Home_Country=wdContext.currentPersonal_DetailsElement().getAttributeAsText("Home_Country");

CreateRecordCommand createRecordCommand =new CreateRecordCommand(connections);

Record r1 = RecordFactory.createEmptyRecord(tables[0].getId());

try

{

// Retrieve Lookup Field Properties, when Field Properties is given as input.

// LookupFieldProperties lookupField = (LookupFieldProperties) fields[9];

//// Retrieve Lookup Field Properties, when Field Properties is given as input.

// LookupFieldProperties lookupFieldSer = (LookupFieldProperties) fieldProp;

// //setting the values for firstname and lastname

r1.setFieldValue(fields[0].getId(),new StringValue(Network_ID));

r1.setFieldValue(fields[2].getId(),new StringValue(First_Name));

r1.setFieldValue(fields[3].getId(),new StringValue(Last_Name));

r1.serFieldValue(FieldValue(fields[9].getId(), new Stringvalue(Home_country));

createRecordCommand.setSession(sessionId);

createRecordCommand.setRecord(r1);

try {

createRecordCommand.execute();

} catch (CommandException e2) {

}

Let me know what are the changes need to be done for inserting the country information in people table.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Please refer to the below link for some sample code.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70a7afe4-9e3e-2b10-de8d-b105d0b8...

Thanks,

Priya.

Answers (1)

Answers (1)

Greg_Austin
Active Participant
0 Kudos

Vijay,

For reading from MDM when you use the getFieldValue method the object returned is an MdmValue object that can be one of several subtypes, StringValue, QualifiedLookupValue, or in your case LookupValue. When you do .toString() on a LookupValue object the R100 you are seeing is the RecordId. Assuming you want the name from the country table and that field is marked as the display field in the MDM console you can use the getLookupDisplayValue method of the Record object.

For saving data you can't assign a StringValue object to the country field because it isn't a text field. You need to create a LookupValue object to pass in the setFieldValue method.

Hope this helps,

Greg

former_member192283
Participant
0 Kudos

Hi Greg,

Thanks for the reply,

Actually,I was doing the same thing what you suggested. I am sending the piece of code . Can look it it .Is any thing wrong.

//inserting the Country lookup filed to record object.

* if(Home_Country.length()!=0)*

* {*

* /when pass the int position number for the country by retreiving from the country table it is working fine. But we cannot depend on position. Because People table internally refering the other db table while inserting the country filed in the People table./ *

* r1.setFieldValue(fields[9].getId(),new LookupValue(new RecordId(12)));*

* *

* //When i PAss the String to the following function i am getting the unsupportedFormat Exception *

* r1.setFieldValue(fields[9].getId(),new LookupValue(new RecordId("Australia")));*

* *

* }*

InCountry . They have defined only two columns called.

1) ISO-2 Code

2) Country Name.

Sample data

ISO-2 Code | Country Name

US United StatesOf America

AU Australia

Ar Argentina

Like the above data we have 250 country names

So , I displaying all the country list in my interface and holding in the Array.

Ex: When the user chooses the Australia. When I pass directly as an "Australia" to

r1.setFieldValue(fields[9].getId(),new LookupValue(new RecordId("Australia"))). it is giving me error.

Then i try to pass the postion of the"Australia" in country table. Like if the Austrila is an 2 record. I am looping through my array and find the record position as "2".

I am passing as

r1.setFieldValue(fields[9].getId(),new LookupValue(new RecordId(2)));

It is inserting into the people database. But not an Australia. It is inserting as "Argentina".

When the record inserting in people table refering some table at the database level , that table called "A2i_16_TEXT" This contains three columns.

A2i_16_TEXT(columns)

1) Id

2) LangId

2) Field Id

4) TextField

Example Data

Id | LangId | Textfield

3 0 Australia

2 0 Argentina

4 0 United States Of America

As i am showing the above table for "Argentina" Id is "2". When i pass the 2 for inserting the country filed.Instead of inserting "Australia". It is inserting the "Argentina" by refering this table.

Through MDM API we are not able to access this " A2i_16_TEXT" table. Because it is maintaining at the db level to find the perticular id for the respective country before inserting in to the people table.

So kindly suggest me how to solve this problem. What i am doing in the code is correct or not.

Regards

Vijay

Greg_Austin
Active Participant
0 Kudos

Hey Vijay,

As you have found you have found you cannot guess a record,s RecordId based on the order it came out of MDM, they are not related. You are going to have to store the RecordId of each country as you read it from MDM to build your drop down. Than later use this RecordId when setting the country. I put the data in a HashMap to relate "Australia" and R3, and to avoid having to loop later.

When you are reading data from MDM:

HashMap countryHash = new HashMap();

As you are looping through the records returned from MDM put the country name and RecordId in the hash. You already know how to get the country name string from the country table record.

countryHash.put(countryName, rec.getId());

Then later when saving the new Record to MDM get the RecordId for Australia from the hash. It will be an Object that you can cast to a RecordId.

countryHash.get("Australia");

Pass this RecordId to the LookupValue constructor.

So instead of this that you had:

r1.setFieldValue(fields[9].getId(),new LookupValue(new RecordId(2)));

Do this:

r1.setFieldValue(fields[9].getId(), new LookupValue(<your RecordId from the hash here>);

Now you don't have to worry if Australia is RecordId 2 or RecordId 50. You should never have to look directly in the database for anything you do in MDM.