2024 Aug 28 4:47 PM - edited 2024 Aug 28 4:52 PM
Hello SAP Community,
I'm facing an issue with the SAP Business One SDK while trying to add a UserField to a table. The error seems related to the reference count of COM objects. Here’s the context:
I have a method that retrieves field information from a source table using a UserFieldsMD object and then attempts to create a similar field in a destination table. I'm using Recordset and UserFieldsMD objects to handle this process.
Here’s a high-level outline of my process:
When I attempt to add this UserField to the destination table, I encounter a refcount error.
I suspect that this issue is related to how COM objects are managed and released within the context of my method, especially since there appears to be a limitation on the number of active COM objects.
Could someone please provide guidance on best practices for managing COM object reference counts when adding UserField objects in SAP Business One SDK? Are there specific patterns or techniques recommended to avoid such errors?
Here is the full code I am using. The error occurs at the CreateField method (line 255):
https://gist.github.com/jonathascosta/6ea59e966c46eb43a74992151f60ab85
Any insights or suggestions on how to properly handle the lifecycle of these COM objects to avoid refcount errors would be greatly appreciated.
Thank you in advance for your assistance!
Request clarification before answering.
To avoid this error please ensure that no other object are running during the addition of the user defined fields. When you are trying to update table/field in the database, you should kill all the running objects and use only the object that the update. You should also set the User Defined Table/User Defined Field to be equal to nothing at the end of the procedure.
In case of DIAPI
oUFields = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
'Add the field code .....................
'IMPORTANT: Release the object
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUFields)
'Then set object variable to Nothing
oUFields = Nothing
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
8 | |
7 | |
5 | |
5 | |
4 | |
4 | |
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.