Skip to Content
author's profile photo Former Member
Former Member

CopyFrom SalesOrder To ProductionOrder

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


If Ret <> 0 Then

MyCompany.GetLastError(IErrCode, x)



MsgBox("Order Created " & x & ".")

End If


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)



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.



Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 01, 2007 at 10:01 AM

    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*


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.