Showing results for 
Search instead for 
Did you mean: 

Delivery Update

0 Kudos


I am working with an Add-on that is Autopacking a Delivery.  The method Delivery.Update is executed for every package in the delivery.  As the packages are created, the update takes longer each iteration.  If a delivery has a larger amount of packages until it eventually will timeout (Approx: 250-300 packages). Here is the portion of the code that calls the update method.

Private Function CreateNewPackage()
    nextpack = GetNextPackNumber(sDocEntry)
    lDocEntry = CLng(sDocEntry)
    Set oDelivery = g_oCompany.GetBusinessObject(oDeliveryNotes)
    oDelivery.GetByKey (lDocEntry)
    Set oTrcPackage = oDelivery.Packages
    oPackage.SetCurrentLine (nextpack - 1)
    oPackage.Number = nextpack
    oPackage.Type = sPackType
    oPackage.UserFields("U_X_UCC").Value = sUCCNum
    oPackage.UserFields("U_X_CARTONCT").Value = lQuantity
    oPackage.Items.ItemCode = sItemCode
    oPackage.Items.Quantity = lQuantity
    oPackage.Units = iWeightUom
    oPackage.UserFields("U_X_BaseEntry").Value = sBaseEntry
    'Puts the Package number on the status bar
    m_oProgBar.Text = nextpack
    If m_sAddSubItemPack = "Y" And m_sTreeType = "S" Then
       'Code to package subitems
    End If

End Function

It appears that due to the long running query, the connection with the Add-On is terminated.  Is there a way to increase the timeout settings or another method of updating the delivery? 

Accepted Solutions (1)

Accepted Solutions (1)

Active Participant
0 Kudos


Try the following (extract from an SAP note 1506163 - UI_UI API break down with RPC error😞


Your add-on is running long-time operations, also the UI API keeps sending events to this add-on. After the long-time operation is done, you may get the error:
Exception: System.InvalidCastException: Unable to cast COM object of
type 'SAPbouiCOM.ApplicationClass' to interface
type 'SAPbouiCOM.IApplication'. This operation failed because the
QueryInterface call on the COM component for the interface with
IID '{D1F75D47-137C-4335-AC2A-3FE209831B6A}' failed due to the
following error: System call failed. (Exception from HRESULT:
0x80010100 (RPC_E_SYS_CALL_FAILED)).



Application Error



One workaround is to set the key “USERPostMessageLimit” in regedit. (To check the path, see the attached file). Make this key large enough like 400,000

Or you can use the RemoveWindowsMessage method which is exposed in 8.82 like this:

System.Threading.Thread.Sleep(1000 * 60);    //replace with your real working code 
SBO_Application.RemoveWindowsMessage(SAPbouiCOM.BoWindowsMessageType.bo_WM_TIMER, true);

This method enables you to deal with extreme scenarios. When an add-on needs to take a long time to process a UI API event, it prevents SAP Business One from processing the Windows message queue.



0 Kudos


Thank you very much for your quick response.  Both solutions that you provided resolve the issue of the long running query causing the connection to the add-on to terminate.  Altering the "USERPostMessageLimit" allowed this issue to be addressed for versions prior to 8.82 where I was able to utilize the RemoveWindowsMessage method.  The oDelivery.Update statement continues to take longer with each package, but it is now able to complete the process.  Any suggestions would be appreciated. 



Answers (0)