Skip to Content
avatar image
Former Member

Modify records with mdm java api

Hi,

I'm trying to modify a recod in MDM via MDM Java API. I want to write an integer value into a field named "Consolidation Flag" in order to mark a record ready for consolidation.

In the "Java API Guide" I have read that the "Change-Stamp" parameter is very important, because the MDM server doesn't modify the record when the changestamp of the old an new records are different.

Because of this, I have tried the following:

1. read the mdm-record from the repository (in order to get the change-stamp)

2. change the field "Consolidation flag" in the original record

3. write it back.

When I modify the field value of an record which has already an update date this will work perfectly. But when the record doesn't have an update date, the field value will not be modify.

Can somebody tell me why? How can I solve this problem?

For modifing I'm using the Class "ModifyRecordsCommand" because I want to modify at least two records at the same time.

Here a piece of Code.

if (records[sourceCounter].getObjectrole().equals("Duplicate")){

+ try{+

+ originalRecords[counter].setFieldValue(fieldId, new IntegerValue(1));+

+ }+

+ catch(MdmValueTypeException e){+

+ e.printStackTrace();+

+ } +

}

else if ....

and later:

ModifyRecordsCommand mrc = new ModifyRecordsCommand(repository.getServer().getConnection());

+ +

mrc.setRecords(originalRecords);

mrc.setSession(repository.getSession().getUserSession());

mrc.setTableId(tableId);

try{

mrc.execute();

}

catch....

Thanks in advance,

Claudia

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Oct 01, 2008 at 09:09 AM

    Hello

    I have almost the same problem. Did you find any sollution for this?

    Regards, Anders

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Claudia,

      I am having similar issue. Can you help me to overcome this.

      I am uisng ModifyRecordsCommand but am getting failure message as "One or more destination records has an invalid change stamp".

      Thanks in Advance

      My Code:

      ArrayList updArrList = new ArrayList();

                                              Record newRecord = null;

                                              int [] succededRecords = null;

                                              int [] failedRecords = null;

                                              MultipleRecordsResult multipleRecordsResultUpd = null;

                                              ModifyRecordsCommand modifyRecordsCommand = new ModifyRecordsCommand(connection.getUserSessionContext());

       

                                              RecordId modifyRecId = null;

       

                                              for(int index =0; index<5; index++){

                                                          modifyRecId = (RecordId)recIdList.get(index);

                                     

                                                          newRecord = RecordFactory.createEmptyRecord(tabId,modifyRecId);

                

                                                         // Setting Values to the corresponding fields

                                                          ManufactureMap mfrMap = new ManufactureMap();

                                                          mfrMap = (ManufactureMap)newMfr.get(index);

       

                                                          String feildCodeName = "MDM_LOCAL_MANUFACTURER_NAME";

                                                          FieldId fiName = DmUtil.getFieldId(connection,mapTable,feildCodeName);

                                                         

                                                          MdmValue mvMfrName = new StringValue(mfrMap.getLocalManfName());

                                                          newRecord.setFieldValue( fiName, mvMfrName );

                                                                                       

                                                          String feildMfrCode = "MDM_LOCAL_MANUFACTURER_CODE";

                                                          FieldId fiMfrCode = DmUtil.getFieldId(connection,mapTable,feildMfrCode);

                                                          MdmValue mvMfrCode = new StringValue(mfrMap.getLocalManfCode());

                                                          newRecord.setFieldValue( fiMfrCode, mvMfrCode ) ;

                 

                                                          RecordId recId = new RecordId("R2");

                                                          String plantFieldCode = "MDM_PLANT";

                                                          FieldId plantFieldId = schema.getFieldId(mapTable,"MDM_PLANT");

                                                          newRecord.setFieldValue(plantFieldId,new LookupValue(recId));// Adding the plant

                 

                                                          String mfrLinkFieldCode = "MFR_LINK";

                                                          FieldId mfrLinkFieldId = DmUtil.getFieldId(connection,mapTable,mfrLinkFieldCode);

                                                          MdmValue mfrLinkValue = new StringValue("mfrLinkChange");

                                                          newRecord.setFieldValue(mfrLinkFieldId,mfrLinkValue);

                                                         

                                                        updArrList.add(index, newRecord);

                                              }

       

                                              Record[] updRecArray = new Record[updArrList.size()];

                                              updRecArray = (Record[])updArrList.toArray(updRecArray);

       

                                              String sessionId = connection.getSessionId();

                                                modifyRecordsCommand.setRecords(updRecArray);

                                              modifyRecordsCommand.setSession(sessionId);

                                              modifyRecordsCommand.setTableId(tabId);

       

                                              try {

                                                                   modifyRecordsCommand.execute();

                                                          multipleRecordsResultUpd = modifyRecordsCommand.getResult();

                                                          Record[] resultArray = modifyRecordsCommand.getRecords();

                                              } catch (Exception e) {

                                                        e.printStackTrace();

                                              }

       

                                              int successCount = multipleRecordsResultUpd.getSucceededRecords().length;

                                              int failCount = multipleRecordsResultUpd.getFailedRecords().length;

       

      //                                        Failure Information

                                               failedRecords = multipleRecordsResultUpd.getFailedRecords(); // Returns index of the failed recordds

                                               int failureCount = failedRecords.length;

                                               String failMsg = "";

                                               for(int f=0;f<failureCount;f++){

                                                         int failRecArrayValue = failedRecords[f];

                                                         failMsg = multipleRecordsResultUpd.getFailedRecordMessage(failRecArrayValue);

                                                         System.out.println("Failed record Message::"+failMsg);

                                               }

                                    }catch(Exception e){

                                              e.printStackTrace();

                                    }

      Regards,

      Vamsi

  • avatar image
    Former Member
    Apr 09, 2009 at 11:11 AM

    Hi,

    I am facing problem for modifying the fields in MDM rapository using MDM java API.I am using the below code and it is giving me the exception

    com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: Information out of date

    code is:

    ConnectionAccessor simpleConnection=null;

    String connection ="psimdm";

    RepositorySchema repositorySchema;

    String session;

    String repository ="repo";

    int totalRecord;

    DBMSType dbmsType =DBMSType.ORACLE;

    RepositoryIdentifier repIdentifier;

    RegionProperties regionProperties;

    try {

    regionProperties = new RegionProperties();

    regionProperties.setLocale(Locale.ENGLISH);

    regionProperties.setName("English US");

    regionProperties.setRegionCode("engUSA"); RegionProperties dataRegion=regionProperties;

    simpleConnection = SimpleConnectionFactory.getInstance("psimdm");

    repIdentifier = new RepositoryIdentifier(repository,"M10",dbmsType);

    CreateUserSessionCommand createUserSessionCommand = new CreateUserSessionCommand(simpleConnection);

    createUserSessionCommand.setRepositoryIdentifier(repIdentifier);

    createUserSessionCommand.setDataRegion(dataRegion);

    createUserSessionCommand.execute();

    session = createUserSessionCommand.getUserSession();

    AuthenticateUserSessionCommand authenticateUserSessionCmd = new AuthenticateUserSessionCommand(simpleConnection);

    authenticateUserSessionCmd.setSession(session);

    authenticateUserSessionCmd.setUserName("test");

    authenticateUserSessionCmd.setUserPassword("");

    authenticateUserSessionCmd.execute();

    GetRepositorySchemaCommand getRepositorySchemaCommand = new GetRepositorySchemaCommand(simpleConnection);

    getRepositorySchemaCommand.setSession(session);

    getRepositorySchemaCommand.execute();

    repositorySchema = getRepositorySchemaCommand.getRepositorySchema();

    TableId tableId= repositorySchema.getTable("Products").getId();

    FieldId[] fields = new FieldId11;

    fields[0] = repositorySchema.getFieldId("Products","Title");

    fields[1] = repositorySchema.getFieldId("Products","Name");

    fields[2]=repositorySchema.getFieldId("Products","DOB");

    fields[3] = repositorySchema.getFieldId("Products","Gender");

    fields[4] = repositorySchema.getFieldId("Products","Marital_Status");

    fields[5]=repositorySchema.getFieldId("Products","Indian");

    fields[6] = repositorySchema.getFieldId("Products","Resident_of_India");

    fields[7] = repositorySchema.getFieldId("Products","Current_Address");

    fields[8]=repositorySchema.getFieldId("Products","City_State");

    fields[9] = repositorySchema.getFieldId("Products","Pin_Code");

    fields10 = repositorySchema.getFieldId("Products","Father_Name");

    Record newRec=RecordFactory.createEmptyRecord(tableId,wdContext.currentContextElement().getRecordID());

    newRec.setFieldValue(fields[0], new LookupValue(wdContext.currentTitle_personalElement().getTitle_ID().getId()));

    newRec.setFieldValue(fields[1], new StringValue("prasanthi1"));

    newRec.setFieldValue(fields[3], new BooleanValue(false));

    Calendar c=Calendar.getInstance();

    c.setTime(wdContext.currentContextElement().getDOB_personal());

    newRec.setFieldValue(fields[2], new DateTimeValue(c));

    newRec.setFieldValue(fields[4], new LookupValue(wdContext.currentMaritalStatus_personalElement().getMaritalStatus_ID().getId()));

    newRec.setFieldValue(fields10, new StringValue("test"));

    ModifyRecordCommand modRec = new ModifyRecordCommand(simpleConnection);

    modRec.setSession(session);

    modRec.setRecord(newRec);

    //wdComponentAPI.getMessageManager().reportSuccess("record modified");

    modRec.execute();

    wdComponentAPI.getMessageManager().reportSuccess("record modified");

    } catch (ConnectionException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    } catch (CommandException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    } catch (IllegalArgumentException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    catch (MdmValueTypeException e1) {

    // TODO Auto-generated catch block

    e1.printStackTrace();

    }

    How to apply the new changestamp for the modified record?

    Add comment
    10|10000 characters needed characters exceeded