Loading
Uniconta
  • Search
  • Uniconta
    • Functions
      • What is Uniconta ?
      • Modules
        • General Ledger
        • Customer
        • Sales order
        • Vendor
        • Purchase
        • Inventory
        • Logistics
        • Project
        • Production
        • CRM
        • Fixed assets
        • AutoBanking
        • Dashboard
        • Company
        • Uniconta Scan
        • Tools
    • Apps and add-ons
      • Assistant App
      • Work App
      • Upload App
      • Paperflow
      • Addon Store
    • Download
      • Uniconta for Windows
      • Download for Developers
      • Free trial signup
  • Developers
    • Become an integration partner
    • Documentation
    • Samples
    • Add-on solutions and users
    • Downloads
  • News
    • Blog
    • News
    • Uniconta Update
    • Customer cases
  • Customer Cases
  • Contact
Search
Generic filters
Free trial signup

Developers Unipedia

  • API
    • API
    • User defined fields
    • User defined tables
    • Saving a Session
    • Posting an Invoice
    • Post Invoice and get PDF
    • Localization
    • Attach physical voucher to entities
    • Server-Login User
    • How to find C# Property from Uniconta Label
    • Minimize network traffic and optimize speed
    • Export pictures from Uniconta
    • OIOUBL Document Mapping and Send (NemHandel)
  • Plugins
    • Plugins
    • Debug Uniconta Plugins
    • Refreshing UI with plugins
    • How to use Uniconta Plugin
    • Develop a user plugin
    • Event Handling
    • Global Script
    • How to capture menu events
    • How to open a form in Uniconta from Plugin
    • Open new content in a IContentPluginBase plugin
    • Adding plugin in a menu
    • How to add user parameter in plugin menu
    • How to create plugin with Devexpress Library
    • Synchronize Entity Support in form page
    • Develop a PageEventBase Plugin
    • Logging Exceptions on local machine
    • Create Custom Uniconta Pages From Github Code
    • Web frame integration
  • OData
    • CRUD operations in OData
    • ODATA REST API – Testing with Postman

User defined tables

July 16th, 2018 January 7th, 2021 2 minutes
Print Friendly, PDF & Email

You can programmatically create and insert user defined tables into Uniconta. First, define a header using the TableHeaderClient class which defines information such as menu position, name and more. Table fields can be added using the TableField class which holds information such as name and type. A good way to create TableFields is to use a POCO model class, and iterate over its properties. You can see this in the example below.

Example

 
public class TableGenerator {
  /* Model class to define fields in our table */
  class MyModel {
    public DateTime Date {
      get;
      set;
    }
    public int EmployeeID {
      get;
      set;
    }
    public string PathToFile {
      get;
      set;
    }
  }
  private CrudAPI _crud {
    get;
    set;
  }
  public TableGenerator(CrudAPI api) {
    _crud = api;
  }
  public async Task < ErrorCodes > CreateTable() {
    var header = new TableHeaderClient {
      _MenuPosition = 0, // 0 = GeneralLedger, 1 = Customer etc.
        _Name = "MyTable", // Name of the table in database.
        _Prompt = "My Table", // Name of the table in client.
        _UserDefinedId = 1234, // Arbitraty ID you can give your table.
        _Attachment = true, // Records can have attachments.
    };
    var headerResult = await _crud.Insert(header);
    if (headerResult != ErrorCodes.Succes) return headerResult;
    var type = typeof (MyModel);
    var fields = new List < TableField > ();
    foreach(PropertyInfo prop in type.GetProperties()) {
      var field = new TableField {
        _Name = prop.Name,
          _Prompt = prop.Name,
          _FieldType = GetFieldType(prop),
      };
      field.SetMaster(header);
      fields.Add(field);
    }
    // Save class file to path
    File.WriteAllText(@ "[Path To Save MyModel.cs]", GetClassString(header, fields.ToArray()));
    return await _crud.Insert(fields);
  }
  /* Helper method to identify field type */
  private CustomTypeCode GetFieldType(PropertyInfo prop) {
    CustomTypeCode type;
    switch (prop.PropertyType.Name.ToString()) {
    case "Double":
      type = CustomTypeCode.Double;
      break;
    case "String":
      type = CustomTypeCode.String;
      break;
    case "DateTime":
      type = CustomTypeCode.DateTime;
      break;
    case "Int32":
      type = CustomTypeCode.Integer;
      break;
    default:
      type = CustomTypeCode.Empty;
      break;
    }
    return type;
  }
  // Generate class string (requires ClientTools.dll)
  private string GetClassString(TableHeader header, TableField[] fields) {
    return ClassGenerator.Create(header, fields, _crud, false);
  }

How To Query your Use Defined Table

In order to query for your user defined table, you must acquire the generated table class.

There are multiple ways to do this.

The easiest way:

  1. Open Uniconta
  2. Tools -> User-defined tables -> Tables
  3. Select your table
  4. Click “Generate C# class”, and select the Client class.
  5. Copy the generated class into your code project and use it like any other table.

Programmatically (Requires ClientTools.dll):

Like shown in GetClassString method of the example code above, we can generate the class string using the ClassGenerator.Create method (from the ClientTools.dll).

For obvious reasons, it is easier to just use the easy way described above, as you only need to generate the class ones. But it is possible to generate the file programmatically too.

After getting the Table class, which looks like this for MyData:

public class MyTable : TableData
{
	public override int UserDefinedId { get { return 1234; } }
	[Display(Name = "Date")]
	public DateTime Date
	{
		get { return this.GetUserFieldDateTime(-1); }
		set { this.SetUserFieldDateTime(-1, value); NotifyPropertyChanged("Date"); }
	}
	[Display(Name = "EmployeeID")]
	public long EmployeeID
	{
		get { return this.GetUserFieldInt64(-1); }
		set { this.SetUserFieldInt64(-1, value); NotifyPropertyChanged("EmployeeID"); }
	}
	[Display(Name = "PathToFile")]
	public string PathToFile
	{
		get { return this.GetUserFieldString(-1); }
		set { this.SetUserFieldString(-1, value); NotifyPropertyChanged("PathToFile"); }
	}
}

You can simply query for records in the table as any other table:

var mytablerecords = await crud.Query<MyTable>();

IMPORTANT NOTE:

The “[Display(…)]” data annotations can be commented out. Your IDE will most likely tell you it doesn’t know the namespace.
This is fine, you can comment it out/remove it. They have no functional purpose.

Categories: API, Developers Unipedia
Home » Developers Unipedia » API » User defined tables

Get in touch with us

Uniconta

  • Uniconta
  • Modules
  • Downloads
  • Free trial signup
  • Subscription Terms
  • Privacy Policy
  • System Status

PARTNER

  • Resellers
  • For Developers
  • Uniconta API key application
  • Uniconta Partner info

INFO

  • News
  • Updates
  • Customer cases
  • Video
  • IT Security
  • Backup procedure
  • About us
  • Management

Support

  • Unipedia
  • API information
  • Contacts
  • Visit a Country Site
    • Dansk
    • Uniconta GermanyDeutsch
    • Eesti
    • Uniconta GermanyÍslenska
    • Lietuva
    • Uniconta NetherlandsNederlands
    • Norsk
    • English
Uniconta
© Copyright 2025 | All rights reserved | info@uniconta.com | Terms & Conditions
Facebook LinkedIn Youtube