cancel
Showing results for 
Search instead for 
Did you mean: 

Create New Record in PRODUCTS Table

Former Member
0 Kudos

Hi,

In the following code, How do i get "R2" value?? Can anyone send me the code to get that value.

I am trying to build an interface for Bulk Upload where i read values from an excel file and create records in Products table where there are lot of lookup fields. I read the value from the excel sheet and need to search that value in lookup table to retreive the recordId right? Can you send me that code?

RecordId recordId = new RecordId("R2");

MdmValue requestValue = new LookupValue(recordId);

If you can give me code snippet for CreateRecordsCommand to create multiple records at a time, it will be great.

Your help is really appreciated.

Thanks

Vijay

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

Hi Vijay,

You will get the RecordId such as R2 by searching the lookup table that you are pointing to from the main table. Check out the RetrieveLimitedRecordsCommand in the javadocs.

-Greg

Former Member
0 Kudos

Hi Sudheendra , Greg, & Arun,

Thanks a lot for your replies, i rewarded points to you all.

I am new to MDM Java API 7.1.

If you get a chance, could you send me the complete code for CreateRecordsCommand, Modify/Update a MDM Record.

Thanks in advance.

Thanks

Vijay

Former Member
0 Kudos

Thanks Nitin for helpful links. Appreciate your help.

Answers (2)

Answers (2)

former_member206107
Active Participant
0 Kudos

Hi Vijay,

You have to perform a search on the lookup table and get the corresponding record ID, please find some sample codes as below,

TableID tid = schema.getTableId("<lookup table Code>");

FieldID Fid = schema.getFieldId("<lookup table Code>","Field ID");

Search obj_Search = new Search(tid);

Search .addSearchItem(new FieldSearchDimension(Fid),new TextSearchConstraint("<input string>", TextSearchConstraint.EQUALS));

RetrieveLimitedRecordsCommand retrieve_Table_records_cmd =

new RetrieveLimitedRecordsCommand(connection);

retrieve_Table_records_cmd .setSearch(MDM_Search);

retrieve_Table_records_cmd .setResultDefinition(rsd);

retrieve_Table_records_cmd .setSession( usersession);

try {

retrieve_Table_records_cmd .execute();

} catch (CommandException e5) {

// TODO Auto-generated catch block

e5.printStackTrace();

}

RecordID Lookup_RID = retrieve_Table_records_cmd.getRecords().getRecord(0).getId();

Best regards,

Arun prabhu S

Former Member
0 Kudos

Arun,

I tried the code you mentioned, but it didn't work. I tried with the following code and it worked.

ResultDefinition rsd = new ResultDefinition(LookupTableid);

rsd.addSelectField(LookupFieldid);

StringValue [] val = new StringValue[1];

val[0] = new StringValue(Exlvalue);

RetrieveRecordsByValueCommand val_command = new RetrieveRecordsByValueCommand(connecPool);

val_command.setSession(usrSessionIdAdm);

val_command.setResultDefinition(rsd);

val_command.setFieldId(LookupFieldid);

val_command.setFieldValues(val);

try {

val_command.execute();

} catch(Exception e) {

wdComponentAPI.getMessageManager().reportWarning("Problem in executing LookupTable: " + e.getMessage());

}

RecordResultSet result_set = val_command.getRecords();

RecordId id = null;

if(result_set.getCount()>0) {

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

id = result_set.getRecord(i).getId();

}

}

//wdComponentAPI.getMessageManager().reportWarning("Record Id: " + id.getIdValue());

return id;

Thanks

Vijay

Former Member
0 Kudos

Hi

Below Code snippet should help you creating records in any MDM Main tables

CreateRecordsCommand createRecComm = new CreateRecordsCommand(connections);

createRecComm.setSession(userSessId);

createRecComm.setRecord(records);

try {

createRecComm.execute();

success = true;

wdComponentAPI.getMessageManager().reportSuccess(

"After inserting record: record:" + rec1);

} catch (CommandException exp) {

wdComponentAPI.getMessageManager().reportException(

exp.getLocalizedMessage(),

false);

success = false;

} catch (Exception exp) {

wdComponentAPI.getMessageManager().reportException(

exp.getLocalizedMessage(),

false);

success = false;

}

Regards