on 03-01-2007 8:39 AM
Hi ,
I am doing a copy to functionality, wherein my code is copying from Orders to Invoice. But when I try to copy from Orders to Production Order it gives me an error on the following line :
oPO = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders)
Error :
Invalid Cast Exception was unhandled
Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbobsCOM.Documents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A6DA575B-E105-4585-9F4B-50CC4044EEDD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I have to do a CopyFrom SalesOrders and CopyTo ProductionOrders on the click of Add Button of SalesOrder. Here is the code what I am executing.
Dim MyCompany As SAPbobsCOM.Company
Dim odocs As SAPbobsCOM.Documents
Dim oPO As SAPbobsCOM.Documents
odocs = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
odocs.CardCode = "c0001"
odocs.DocDate = Now
odocs.DocDueDate = Now
odocs.Lines.ItemCode = "A00007"
Ret = odocs.Add
Dim x As String
Dim IErrCode As Integer
MyCompany.GetNewObjectCode(x)
If Ret <> 0 Then
MyCompany.GetLastError(IErrCode, x)
MessageBox.Show(x)
Else
MsgBox("Order Created " & x & ".")
End If
createProductionOrder(x)
End Sub
Public Sub createProductionOrder(ByVal x As String)
oPO = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders) on the this line it gives the error as mentioned above.
oPO.DocNum = x
oPO.DocDate = Now
oPO.DocDueDate = Now
oPO.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
oPO.Lines.BaseEntry = x
Ret = oPO.Add
Dim IErrCode As Integer
If Ret <> 0 Then
MyCompany.GetLastError(IErrCode, x)
MessageBox.Show(x)
Else
MsgBox("Production Order Created " & x & ".")
End If
End Sub
Thanks if any one can look into the code and give me the correct code to solve my solution of Coping the SalesOrders to ProductionOrder. Or can give me an alterante code/solution.
Thanks
Murtaza
You have declared oPO as type SAPbobsCOM.Documents - production orders are not documents, they are of type SAPbobsCOM.ProductionOrders. This is the cause of your error message.
There are no built in facilities for copying standard document objects to production orders through BaseType/BaseEntry properties - these properties do not even exist on a production order.
You will need to create a new Production Order object, and set all the properties explicitly through code. Your code will need to look something like the following:-
Dim sboProdOrder As SAPbobsCOM.ProductionOrders
Set sboProdOrder = sboCompany.GetBusinessObject(oProductionOrders)
sboProdOrder.ProductionOrderType = bopotStandard
sboProdOrder.ItemNo = *INSERT ITEM CODE FROM ORDER LINE*
sboProdOrder.PlannedQuantity = *INSERT QTY FROM ORDER LINE*
sboProdOrder.CustomerCode = *INSERT CARDCODE FROM ORDER*
sboProdOrder.ProductionOrderOrigin = bopooSalesOrder
sboProdOrder.ProductionOrderOriginEntry = *INSERT DOCENTRY FROM ORDER*
sboProdOrder.DueDate = *INSERT DATE FROM ORDER*
sboProdOrder.Add
John.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
6 | |
5 | |
5 | |
5 | |
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.