cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Modifying fields using MDM java API

Former Member
0 Kudos

Hi,

I am using below code for modifying records usind MDM java API. There seems to be some problem with my modify command, not able to modify the fields in the MDM repository.

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 FieldId[11];

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

fields[10] = 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(fields[10], 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();

}

i am able to get the table ID and field IDs. Modify command is giving some problem. Kindly suggest.

Edited by: prasanthi reddy on Apr 9, 2009 11:48 AM

Edited by: prasanthi reddy on Apr 9, 2009 11:51 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I am getting below exception. Anybody have some idea why it is coming?

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

Former Member
0 Kudos

Hi Prasanthi,

In addition set one more parameter

setModifyAnyway(true);

Before executing the command ModifyRecordsCommand

Regards,

Jitesh Talreja

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

I am not gettimg exceptions (CommandException) while  running ModifyRecordsCommand,but when I check MultipleRecordResult as follows,

MultipleRecordsResult multipleRecordsResult=commandd.getResult();

multipleRecordsResult.getFailedRecordMessage();

I will get message "Could not modify record".

There is no other exception  thrown.What could be the reason for failing this modification operation?Is it related to ChangeStamp?

Please help on this issue.

Thanks,

Anuja


Former Member
0 Kudos

Hi,

I am using ModifyRecordCommand for modyfing record.After executing command no exception is thrown,but record is not getting modifyied.

I can use ModifyRecordsCommand,but it does not have setModifyAnyway() option.But I needsetModifyAnyway(true) option.

Please help on this issue.

Thanks,

Anuja

Former Member
0 Kudos

Hi Prasanthi/Becky,

Can you please update us on your issue? This would be helpful for all those working on MDM Java APIs

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Prasanti,

Information out of date error is generally caused due to the ChangeStamp. You need to set the changestamp before updating the record in MDM. Try setting the changestamp in RS and then try.

Cheers,

Arafat

Former Member
0 Kudos

modify command is not working...

if i print the filed ID's i am passing, they are giving the result. Table ID and Record ID are also proper.

I am not able to print a message also after the execution of modify command. The control is going only till the beggining of executeModify conmmand.

Former Member
0 Kudos

Hi Prasanthi,

It must be throwing some exception. Remove all the catch statements and write the below code

Catch(Exception e)

{

wdComponentAPI.getMessageManager().reportSuccess("Exception Occured"+e.toString());

}

With this you will get the exact the reason why it is failing

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Jitesh/Prasanthi,

I am also facing the same problem while updating.

Jitesh, can u tell us how to set the changestamp using APIs.

Regards,

Becky.

Former Member
0 Kudos

Hi Jitesh,

I am getting following exception:

Exception Occuredcom.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: Type mismatch

please suggest.

Former Member
0 Kudos

Hi Prasanthi/Becky,

Check the below code

ModifyRecordCommand modRec = new ModifyRecordCommand(simpleConnection);

modRec.setSession(session);

modRec.setRecord(newRec);

modrec.setModifyAnyway(true); //this accepts the boolean parameter and the value is case sensitive

modRec.execute();

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

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Becky,

this error is most probably due to a wrong assignment. Like it will occur if you are trying to update a Lookup Field with a test value or vice versa.

Please check if you have correct assignments for all the fields.

Cheers,

Arafat

Former Member
0 Kudos

Hi Prasanthi,

Exactly what problem you are facing?

Refer the below thread for your reference

Regards,

Jitesh Talreja