cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API 2

Former Member
0 Kudos

How to check out records using the Java API 2?

How to check in records using the Java API 2?

How to determine the Check out status of the record using the Java API 2?

Any code snippet is appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

check if this will help you out :


                                                                           
1)create a record                                                                                
TableId mainTableId = new TableId(mdmTable.getTableId                         
(MdmTable.PRODUCTS));                                                         
CreateRecordCommand createRecord = new CreateRecordCommand(conn);#            
Record rec = RecordFactory.createEmptyRecord(mainTableId);                                                                                
StringValue numberValue = new StringValue("Test ");                                                                                
createRecord.setRecord(rec);                                                  
createRecord.setSession(session);                                             
try {                                                                         
createRecord.execute();                                                      
recordId = createRecord.getRecord().getId();                                 
recordId = setCheckOut(recordId);                                            
} catch (CommandException e) {                                                
// TODO Auto-generated catch block                                           
e.printStackTrace();                                                         
}                                                                                
2)check out the newly created record                                                                                
private RecordId setCheckOut(RecordId recordId){          
RecordId recordCheck = null;                                                                                
TableId table = new TableId( mdmTable.getTableId         
(MdmTable.PRODUCTS));                                                                                
RecordId[] records = new RecordId[1];                    
records[0] = recordId;                                                                                
CheckoutRecordsCommand checkoutCommand = new             
CheckoutRecordsCommand(conn);                             
checkoutCommand.setSession(session);                     
checkoutCommand.setTableId(table);                       
checkoutCommand.setExclusive(false);                     
checkoutCommand.setRecordIds(records);                   
  try {                                                             
checkoutCommand.execute();                                       
RecordId[] recs = checkoutCommand.getCheckOutRecordIds           
();                                                                
recordCheck = recs[0];                                                                                
} catch (CommandException e) {                                    
// TODO Auto-generated catch block                               
e.printStackTrace();                                             
}                                                                 
return recordCheck;

3)Modify the checked out record (the CheckoutRecordCommand returns an   
array of Ids , we then use these ids to modify the checked out record)  
                                                                        
ModifyRecordCommand modifyRecord = new ModifyRecordCommand(conn);       
modifyRecord.setSession(session);                                       
modifyRecord.setRecord(record);                                         
modifyRecord.setModifyAnyway(false);                                    
modifyRecord.execute();                                                 


4)then we can go ahead an check in / rollback the record                                                                                
RollbackRecordsCommand rollbackCommand = new RollbackRecordsCommand 
(conn);                                                             
rollbackCommand.setSession(session);                                
rollbackCommand.setTableId(tableId);                                
rollbackCommand.setRecordIds(recs);                                 
rollbackCommand.execute();                                                                                
or                                                                  

CheckinRecordsCommand checkinCommand = new CheckinRecordsCommand(conn); 
checkinCommand.setSession(session);                                     
checkinCommand.setRecordIds(recs);                                      
checkinCommand.setTableId(tableId);                                     
checkinCommand.execute()                                                                                

cheers

Answers (3)

Answers (3)

Former Member
0 Kudos

I get an exception when using CheckoutRecordsCommand:

ServerException: "Not yet implemented"

Has this been working once?

Former Member
0 Kudos

Amol,

I have the Java Docs.

I am looking if someone has done checking out using the new API.

The examples in the java doc are insufficient to the cause.

amolgupta
Active Contributor
0 Kudos

hi,

this link has java docs, code snippets, etc..

http://help.sap.com/javadocs/MDM/current/index.html