/ITCO-SBO-Addon-Framework

Framework for SAP Business One SDK Addons

Primary LanguageC#MIT LicenseMIT

SAP Business One Addon Framework

Framework for SAP Business One SDK Addons

NuGet version itcompaniet MyGet Build Status

Usage UI API

Create an Windows Application Project and run SboAddonContext() from Main.

Connection to SBO will be made automatically.

static class Program
{
    [STAThread]
    static void Main()
    {
        Application.Run(new SboAddonContext());
    }
}

Form Controller

MyFormController will automaticly load Forms.MyForm.srf and create an menu item.

    public class MyFormController : FormController, IFormMenuItem
    {
        public string MenuItemTitle => "My Form";
        public string ParentMenuItemId => SboMenuItem.Finance;
    }

Usage DI API

Connect

static class Program
{
    static void Main()
    {
        // From app.config
        SboApp.DiConnectFromAppConfig();
    }
}
  <appSettings>
    <add key="Sbo:ServerName" value="SAP-SERVER"/>
    <add key="Sbo:ServerType" value="MSSQL2014"/>
    <add key="Sbo:CompanyDb" value="SBODemo"/>
    <add key="Sbo:DbUsername" value="sa"/>
    <add key="Sbo:DbPassword" value=""/>
    <add key="Sbo:Username" value="manager"/>
    <add key="Sbo:Password" value=""/>
    <add key="Sbo:LicenceService" value="SAP-SERVER:30000"/>
  </appSettings>

Setup Class

    public class MySetup : ISetup
    {
        public const string UDT_MyData = "ITCO_Mydata";
        public const string UDF_CardCode = "CardCode";
        public const string UDF_Amount = "Amount";

        public int Version => 1;

        public void Run()
        {
            UserDefinedHelper.CreateTable(UDT_MyData, "My Data")
                .CreateUDF(UDF_CardCode, "CardCode", BoFieldTypes.db_Alpha, 30)
                .CreateUDF(UDF_Amount, "Amount", BoFieldTypes.db_Float, 30, BoFldSubTypes.st_Price);

            SettingService.InitSetting<string>("my.setting.1", "My Setting 1", "value123");
            SettingService.InitSetting<int>("my.setting.2", "My Setting 2", 0);
        }
    }

Run setup

// Finds and run all ISetup classes
SetupManager.FindAndRunSetups(GetType().Assembly);
// or run manually
SetupManager.RunSetup(new MySetup());

Settings Service

var mySetting = SettingService.GetSettingByKey("itco.mysetting", 0);

Recordset Query

using (var query = new SboRecordsetQuery("SELECT [DocNum] FROM [ORDR]"))
{
    if (query.Count == 0)
        SboApp.Application.MessageBox("No Matches!");

    foreach (var row in query.Result)
    {
        var docNum = row.Item("DocNum").Value;
    }
}

Misc Helpers

var combobox = Form.GetComboBox("MyCombo");
combobox.AddComboBoxValues("SELECT CardCode, Cardname FROM OCRD");