on 2013 Feb 02 4:51 AM
Hi all experts,
i create add on to let user to browse and attach their file to server.
I use sap function as below:
For i As Integer = 0 To Me.DataGridView1.RowCount - 1
Dim so As SAPbobsCOM.SalesOpportunities
so = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesOpportunities)
Dim oid As Integer, Path As String, filename As String, extention As String, docdate As String
oid = Me.DataGridView1.Item(0, i).Value
Path = Me.DataGridView1.Item(1, i).Value
filename = System.IO.Path.GetFileNameWithoutExtension(Path & Me.DataGridView1.Item(2, i).Value)
extention = System.IO.Path.GetExtension(Path & Me.DataGridView1.Item(2, i).Value)
extention = Mid(extention, 2)
docdate = Me.DataGridView1.Item(3, i).Value
Dim oAtt As SAPbobsCOM.Attachments2
oAtt = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2)
oAtt.Lines.SourcePath = Path
oAtt.Lines.FileName = filename
oAtt.Lines.FileExtension = extention
oAtt.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES
iRet = oAtt.Add
If iRet = 0 Then
Dim key As String = ""
Dim absoluteEntry As Integer
PublicVariable.oCompany.GetNewObjectCode(key)
absoluteEntry = Integer.Parse(key)
If so.GetByKey(oid) = True Then
so.AttachmentEntry = absoluteEntry
iRet = so.Update
Else
tbl.Rows.Add(oid, Path, filename, docdate)
End If
End If
Next
Me.DataGridView1.DataSource = Nothing | |
Me.DataGridView1.DataSource = tbl |
-For this code, I use all SAP Building Object and Function. but it doesn't copy to server
-it is also save only the last attachment file
Does anybody help me about this?
Thanks
Hi Sok,
In your code you are looping over a datagrid and in that loop you get one sales opportunity (which is given in the datagrid), and create one attachment with one file per line on the datagrid. Then you assign the attachment to the sales opportunity and update.
This is why it seems only the last file is saved. What you must do is loop over the datagrid but add more lines to the same attachment (please note that the same attachment can contain multiple files).
e.g.:
Attachment1
- File 1 // these are the lines of the attachment
- File 2
- File 3
The example above is one attachment with 3 files.
Dim so As SAPbobsCOM.SalesOpportunities
Dim oAtt As SAPbobsCOM.Attachments2
Dim oid As Integer, Path As String, filename As String, extention As String, docdate As String
so = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesOpportunities)
oAtt = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2)
oid = Me.DataGridView1.Item(0, i).Value -> the value for the oid must be the same in all the lines (or else more work is needed)
For i As Integer = 0 To Me.DataGridView1.RowCount - 1
Path = Me.DataGridView1.Item(1, i).Value
filename = System.IO.Path.GetFileNameWithoutExtension(Path & Me.DataGridView1.Item(2, i).Value)
extention = System.IO.Path.GetExtension(Path & Me.DataGridView1.Item(2, i).Value)
extention = Mid(extention, 2)
docdate = Me.DataGridView1.Item(3, i).Value
oAtt.Lines.SourcePath = Path
oAtt.Lines.FileName = filename
oAtt.Lines.FileExtension = extention
oAtt.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES
oAtt.Lines.Add
Next
iRet = oAtt.Add
If iRet = 0 Then
Dim key As String = ""
Dim absoluteEntry As Integer
PublicVariable.oCompany.GetNewObjectCode(key)
absoluteEntry = Integer.Parse(key)
If so.GetByKey(oid) = True Then
so.AttachmentEntry = absoluteEntry
iRet = so.Update
Else
tbl.Rows.Add(oid, Path, filename, docdate)
End If
End If
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.DataSource = tbl
The changes were not tested.
Regarding the copying to the server of the files you've been answered in your previous post. Take a look at and posts.
Good luck.
Best regards,
Pedro Magueija
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
9 | |
8 | |
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.