on 04-09-2010 10:51 AM
Hi
How to store attachments in MDM repository using MDM java API.
Could you please suggest us.
Thanks
Sowmya
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Hi Sowmya,
You can use CreateBinaryRecordCommand for saving attachments in Binary Objects table in MDM.
Cheers,
Arafat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.