Search code examples
c#.netsapb1sap-business-one-di-api

How to get a list of all company accounts?


I'm trying to get list of all company accounts using SAP Business One (B1 or BO) Data Interface API (DI API) for .NET.
An account is represented as ChartOfAccounts SDK's type.
I can't figure out if there is a way to do something like this (it's how I'm getting the list of items):

    var oItem = (Items) Company.GetBusinessObject(BoObjectTypes.oItems);
    var oSBObob = (SBObob)Company.GetBusinessObject(BoObjectTypes.BoBridge);
    var oRecordSet = oSBObob.GetItemList();

But it seems there is no method to similar to GetItemList() for accounts in SBObob type.

Does anybody know how to get list of company accounts?


Solution

  • I implemented this using a Recordset approach by querying OACT DB table directly for the list of account keys (AcctCode DB field) and then using ChartOfAccounts's GetByKey() method to fill other ChartOfAccounts's fields like this:

                var sapAccount = (ChartOfAccounts)Company.GetBusinessObject(BoObjectTypes.oChartOfAccounts);
                var oRecordSet = (Recordset)company.GetBusinessObject(BoObjectTypes.BoRecordset);
                oRecordSet.DoQuery("SELECT AcctCode FROM OACT");
    
                while (!oRecordSet.EoF)
                {
                    var key = oRecordSet.Fields.Item(0).Value.ToString();
                    sapAccount.GetByKey(key)
    
                    // Now sapAccount is filled with current account data - do something with its fields
    
                    oRecordSet.MoveNext();
                }