on 09-10-2014 8:07 AM
Hi
how can I add attachments into Oitm object?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
try to creata filed and Button and browse and save to DB.
Imports System.Threading
Imports System.IO
Sub OpenFile()
Try
ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)
If ShowFolderBrowserThread.ThreadState = ThreadState.Unstarted Then
ShowFolderBrowserThread.SetApartmentState(ApartmentState.STA)
ShowFolderBrowserThread.Start()
ElseIf ShowFolderBrowserThread.ThreadState = ThreadState.Stopped Then
ShowFolderBrowserThread.Start()
ShowFolderBrowserThread.Join()
End If
Catch ex As Exception
End Try
End Sub
Public Sub ShowFolderBrowser()
Try
Dim omat As SAPbouiCOM.Matrix = PI_Frm.Items.Item("m_attach").Specific
Dim MyTest As New OpenFileDialog
Dim MyProcs() As Process
Dim filename As String
MyProcs = Process.GetProcessesByName("SAP Business One")
If MyProcs.Length <> 0 Then
For i As Integer = 0 To MyProcs.Length - 1
Dim MyWindow As New WindowWrapper(MyProcs(i).MainWindowHandle)
MyTest.Filter = "Excel files (.xls)|.xls|Document files (.doc)|.doc"
MyTest.InitialDirectory = "C:\"
If MyTest.ShowDialog(MyWindow) = DialogResult.OK Then
filename = MyTest.FileName
Dim f As New System.IO.FileInfo(filename)
PI_Frm.Freeze(True)
omat.AddRow()
omat.FlushToDataSource()
ATTACH_oDBds.Offset = ATTACH_oDBds.Size - 1
ATTACH_oDBds.SetValue("LineId", ATTACH_oDBds.Offset, omat.VisualRowCount)
ATTACH_oDBds.SetValue("U_path", ATTACH_oDBds.Offset, f.DirectoryName)
ATTACH_oDBds.SetValue("U_fname", ATTACH_oDBds.Offset, f.Name)
ATTACH_oDBds.SetValue("U_adate", ATTACH_oDBds.Offset, DateTime.Today.ToString("yyyyMMdd"))
omat.SetLineData(ATTACH_oDBds.Size)
' omat.FlushToDataSource()
PI_Frm.Items.Item("Display").Enabled = True
PI_Frm.Items.Item("Delete").Enabled = True
PI_Frm.Freeze(False)
System.Windows.Forms.Application.ExitThread()
Else
System.Windows.Forms.Application.ExitThread()
End If
Next
Else
Console.WriteLine("No SBO instances found.")
End If
Catch ex As Exception
PI_Frm.Freeze(False)
End Try
End Sub
regards,
Prasad
Hi Feliciello,
As said by Pedro, this property not exposed by the DI-API: neither in 9.0 nor (up to PL01) in 9.1.
Except if the DI-API is modified by SAP, the only way to achieve what you want is to do a direct update Inside the OITM table, but we all know this is an unsupported way to do...
Regards,
Eric
Thanks but I have to do it using sdk.
I've founded a workaroud that customer can accept:
I have to add a new activity with a predefinied object linked to the OITM with all attachments
with SDK I've added the new activity (OCLG) linked to an OITM
but I don't know how to create new attachments into the new acivity.
I did a lot of tests using attachments2 object, but it doesn't work.
Have you got an example? Thanks
Hi Feliciello,
This is how to use the Attachments2 object.
SAPbobsCOM.Attachments2 oATT = eCommon.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2) as SAPbobsCOM.Attachments2;
string FileName = "C:\Test\MyTest.txt";
oATT.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);
oATT.Lines.FileExtension = System.IO.Path.GetExtension(FileName).Substring(1);
oATT.Lines.SourcePath = System.IO.Path.GetDirectoryName(FileName);
oATT.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;
//If you need to add more files :
//oATT.Lines.Add();
//The file info here
int lErr = oATT.Add();
Take the Created Object Key and feed it into your Activity.AttachmentEntry
Regards
Edy
Ok
I've already found this source
my problem in an other
I have to add an activity with attachmnets, my code is the follow it create the activity but doesn't attach anyting. Can you help me? Thanks
oAct = (SAPbobsCOM.Activity)oActivityServ.GetDataInterface(SAPbobsCOM.ActivitiesServiceDataInterfaces.asActivity);
//oAct.CardCode = oBP.CardCode;
//oAct.HandledByEmployee = 2;
//oAct.ActivityDate = DateTime.Parse("28/11/2012");
//lClgCode = lClgCode + 1;
//oAct.ActivityCode = lClgCode;
oAct.ActivityDate = dttm;
oAct.StartDate = dttm;
oAct.StartTime = dttm;
oAct.EndTime = dttm;
oAct.Activity = SAPbobsCOM.BoActivities.cn_Other;
oAct.ActivityType = iIDTipo;
oAct.Subject = iIDOggetto;
sVal = Left(sOggetto, 100);
oAct.Details = sVal;
oAct.Notes = sVal;
iVal = 4;
oAct.DocType = iVal.ToString().Trim();
oAct.DocEntry = sKeyItem;
/*oActParams = oActivityServ.AddActivity(oAct);
lAggiunti = lAggiunti + 1;
if (oCompany.InTransaction)
{
//oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
}
else
{
throw new Exception("ERROR: Transaction closed before EndTransaction");
}
oCompany.StartTransaction();
*/
oAttach = (SAPbobsCOM.Attachments2)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
int iAttchEntry = oAct.AttachmentEntry;
if (oAttach.GetByKey(iAttchEntry))
{
b_TestNewTMP = true;
iMax = oAttach.Lines.Count - 1;
b_TestFirst = true;
if (b_TestExist)
{ //never enter here
for (i = 0; i <= iMax; i++)
{
oAttach.Lines.SetCurrentLine(i);
sVal = oAttach.Lines.FileName.Trim();
if (sVal != "")
{
....
}
}
}
sVal = Path.GetFileNameWithoutExtension(sFilePath);
oAttach.Lines.FileName = sVal;
sVal = Path.GetExtension(sFilePath);
sVal = sVal.Replace(".", "");
oAttach.Lines.FileExtension = sVal;
sVal = Path.GetDirectoryName(sFilePath);
oAttach.Lines.SourcePath = sVal;
sDestinationFile = path + Path.GetFileName(sFilePath);
oAttach.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;
if (File.Exists(sDestinationFile))
{
System.IO.File.Delete(sDestinationFile);
}
lRetCode = oAttach.Add();
if (lRetCode != 0)
{
oCompany.GetLastError(out lErrCode, out sErrMsg);
sVal = "(Art." + sKeyItem + ")";
textErrors.AppendText(sVal + ": " + sErrMsg + " (" + lErrCode + ")\r\n");
return;
}
Hi Feliciello,
Follow this step :
1. Start Transaction.
2. Create Attachment object and upon success, get the AttachementEntry from oCompany.GetNewObjectKey()
3. Create Activity.
Before you Add the Activity into database, set the oAct.AttachmentEntry = The Attachment Entry you get from point 2 above.
4. Commit the transaction.
Regards
Edy
User | Count |
---|---|
85 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.