1

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • There's no obvious parallel to GetItemList() for GL accounts mentioned in the SDK. You could get a recordset by directly querying the OACT table. – Daz Nov 22 '16 at 21:38
  • @Daz: Thank you, I actually implemented it exactly the way you've suggested - please see my answer below. It just seemed to me like a frequent use case of SDK classes and I hoped its classes may contain a convenience method to perform it without researching of DB schema and relying on the SQL queries. – Alexander Abakumov Nov 22 '16 at 23:18

1 Answers1

2

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();
            }
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129