cancel
Showing results for 
Search instead for 
Did you mean: 

Attachments using MDM java API

Former Member
0 Kudos

Hi

How to store attachments in MDM repository using MDM java API.

Could you please suggest us.

Thanks

Sowmya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sowmya,

You can store attachments using MDM Java API. You can use the following piece of code.

BinaryBlobRecord record2 = RecordFactory.createEmptyBinaryObjectRecord(tableID);

//Attachment to be saved
String filePath = wdContext.currentContextElement().getVa_Resource().getUrl(0);
	
IWDResource resource = wdContext.currentContextElement().getVa_Resource();
	
FileInputStream stream = (FileInputStream)resource.read(true);
	
	
int length = 0;
while(stream.read() != -1)
{
	length++;
}
	
byte[] b = new byte[(int) length];
stream.read(b);
stream.close();
	
record.setName(new StringValue("filename"));
record.setOriginalName(new StringValue("filename"));
record.setHasOriginal(new BooleanValue(true);
	
RetrieveGroupTreeCommand groupTreeCommand = new    RetrieveGroupTreeCommand(wdContext.currentContextElement().getVa_ConnectionStr());
groupTreeCommand.setSession(wdContext.currentContextElement().getVa_SessionID());
groupTreeCommand.setGroupType(GroupTypes.DATA_GROUP_TYPE);
groupTreeCommand.execute();

//Set data location and data group ID
record.setDataLocationId(new GroupNodeId("GN2"));
record.setDataGroupId(new GroupNodeId("GN2"));

record.setBinary(new BinaryValue(b));

CreateRecordCommand createRecComm =
					new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
createRecComm.setRecord(record);
	
createRecComm.execute();

//Link this record to the main table record
Record QRec = RecordFactory.createEmptyRecord(mainTable);

//Setting the above created record in main table record object
QRec.setFieldValue(attachmentField, new LookupValue(record.getId()));
	
CreateRecordCommand createRecComm =
				new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
createRecComm.setRecord(QRec);
	
createRecComm.execute();

Now the main table record is created with an attachment.

Hope this helps you.

Regards,

Sruti

Former Member
0 Kudos

I have done same thing.. But When I am running I am getting the below error

"errorcom.sap.mdm.internal.protocol.manual.ServerException: Server error (0xffaab000) "

Could you please help me in resolving this error.

Thanks

Sowmya

Former Member
0 Kudos

This guide may be helpfule to you....

[http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/a099a3bd-17ef-2b10-e6ac-9c1ea42af0e9]

Cheers,

Rc

Former Member
0 Kudos

Hi Shruti

Can you please let me know what is the significance of the value "GN2" in the below statements.

Is it some Standard Constants/Qualifiers??(I tried finding but no luck)

It will be very helpful, if you provide the details, as i was also facing the issue but when i used GN2 it worked, but the issue now is that it is working for me on one server but on another server its giving the following issue "server error (0xffaab000) [RC_CM_LOCATIONNOTFOUND]"

record.setDataLocationId(new GroupNodeId("GN2"));

record.setDataGroupId(new GroupNodeId("GN2"));

Thanks and Regards

Osman Abdul Aziz Jabri

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sowmya,

You can use CreateBinaryRecordCommand for saving attachments in Binary Objects table in MDM.

Cheers,

Arafat

former_member205403
Active Contributor
0 Kudos

Hi,

If you have missed then please check [MDM Java API Guide|http://help.sap.com/saphelp_nwmdm71/helpdata/en/72/d36e1ed3ce43028adc851b8fed5668/MDM_Java_Net_API_Guide.pdf] (page no 54 onwards) for details and code sample.

Regards,

Shiv