on 11-24-2009 12:17 PM
Hi All,
How to add purchase order using code (not using object-id of PO form)
1.I want to create Purchase order dynamically.
I tried with following code
Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
'Create the Documents object
Dim vPurchaseOrder As SAPbobsCOM.Documents
vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
'Set values to the fields
'vPurchaseOrder.Series = 0
vPurchaseOrder.Series = 0
vPurchaseOrder.CardCode = "BP234"
vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
vPurchaseOrder.PaymentGroupCode = "-1"
vPurchaseOrder.DocDate = DateTime.Today
vPurchaseOrder.DocTotal = 264.6
'Invoice Lines - Set values to the first line
vPurchaseOrder.Lines.ItemCode = "A00023"
vPurchaseOrder.Lines.ItemDescription = "Banana"
vPurchaseOrder.Lines.PriceAfterVAT = 2.36
vPurchaseOrder.Lines.Quantity = 50
vPurchaseOrder.Lines.Currency = "Eur"
vPurchaseOrder.Lines.DiscountPercent = 10
'Invoice Lines - Set values to the second line
vPurchaseOrder.Lines.Add()
vPurchaseOrder.Lines.ItemCode = " A00033"
vPurchaseOrder.Lines.ItemDescription = "Orange"
vPurchaseOrder.Lines.PriceAfterVAT = 118
vPurchaseOrder.Lines.Quantity = 1
vPurchaseOrder.Lines.Currency = "Eur"
vPurchaseOrder.Lines.DiscountPercent = 10
vPurchaseOrder.Lines.Add()
vPurchaseOrder.Lines.ItemCode = " A00034"
vPurchaseOrder.Lines.ItemDescription = "mangoOrange"
vPurchaseOrder.Lines.PriceAfterVAT = 118
vPurchaseOrder.Lines.Quantity = 1
vPurchaseOrder.Lines.Currency = "Eur"
vPurchaseOrder.Lines.DiscountPercent = 10
'Add the Invoice
RetVal = vPurchaseOrder.Add
'Check the result
If RetVal 0 Then
'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
MsgBox(ErrCode & " " & ErrMsg)
End If
This code shows error
Datasource no data fond...!!!
Here directly im assigning values . How we can assign datssource to this code
by
Firos
Hello,
please find my comments in your code
Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
'Create the Documents object
Dim vPurchaseOrder As SAPbobsCOM.Documents
vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
'Set values to the fields
'J: Not need or you sould read a correct value from ONNM and NNM1 tables.
' vPurchaseOrder.Series = 0
vPurchaseOrder.CardCode = "BP234"
vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
' Automatic, populated by BP master data vPurchaseOrder.PaymentGroupCode = "-1"
vPurchaseOrder.DocDate = DateTime.Today
' Filled by DI API, not needed vPurchaseOrder.DocTotal = 264.6
'Invoice Lines - Set values to the first line
vPurchaseOrder.Lines.ItemCode = "A00023"
' Filled by DI API, not needed , but if you give a different name necessary vPurchaseOrder.Lines.ItemDescription = "Banana"
' Filled by DI API, not needed vPurchaseOrder.Lines.PriceAfterVAT = 2.36
'Use UnitPrice or Price up to the Customizing. Pure 2007 version apply UnitPrice upgarded from prevoius versions check document settings
vPurchaseOrder.Lines.UnitPrice = 2.36
vPurchaseOrder.Lines.Quantity = 50
' Filled by DI API, not needed should be defined in header level vPurchaseOrder.Lines.Currency = "Eur"
vPurchaseOrder.Lines.DiscountPercent = 10
'Invoice Lines - Set values to the second line
vPurchaseOrder.Lines.Add()
'missing
vPurchaseOrder.SetCurrentLine(1)
vPurchaseOrder.Lines.ItemCode = " A00033"
vPurchaseOrder.Lines.ItemDescription = "Orange"
'Filled by DI API, not needed vPurchaseOrder.Lines.PriceAfterVAT = 118
vPurchaseOrder.Lines.Quantity = 1
vPurchaseOrder.Lines.Currency = "Eur"
'Use UnitPrice or Price up to the Customizing. Pure 2007 version apply UnitPrice upgarded from prevoius versions check document settings vPurchaseOrder.Lines.UnitPrice = 118
vPurchaseOrder.Lines.DiscountPercent = 10
'Add the Invoice
RetVal = vPurchaseOrder.Add
'Check the result
If RetVal 0 Then
'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
MsgBox(ErrCode & " " & ErrMsg)
End If
Regards
János
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
Mistake inside, sorry. The Correct Is: Document.Lines.SetCurrentLine()
Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim vPurchaseOrder As SAPbobsCOM.Documents
vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
vPurchaseOrder.CardCode = "BP234"
vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
vPurchaseOrder.DocDate = DateTime.Today
vPurchaseOrder.Lines.ItemCode = "A00023"
vPurchaseOrder.Lines.UnitPrice = 2.36
vPurchaseOrder.Lines.Quantity = 50
vPurchaseOrder.Lines.DiscountPercent = 10
vPurchaseOrder.Lines.Add()
vPurchaseOrder.Lines.SetCurrentLine(1)
vPurchaseOrder.Lines.ItemCode = " A00033"
vPurchaseOrder.Lines.ItemDescription = "Orange"
vPurchaseOrder.Lines.Quantity = 1
vPurchaseOrder.Lines.UnitPrice = 118
vPurchaseOrder.Lines.DiscountPercent = 10
'Add the Invoice
RetVal = vPurchaseOrder.Add
'Check the result
If RetVal 0 Then
'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
MsgBox(ErrCode & " " & ErrMsg)
End If
Regards,
J.
The value of series is 0.Chek if this value is correct.
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 | |
12 | |
11 | |
6 | |
6 | |
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.