Setting up
You can create user defined fields in the Tools/User defined fields menu.
Choose which table you would like to add a new field to, e.g. ‘Inventory’, ‘Sales orders’ etc.
The two most important fields to set are ‘Name’ and ‘Type’. ‘Name’ being the name of the field in the database, and ‘Type’ being its type, e.g. String, Integer, Boolean etc.
‘Group name‘ is used if you wish to group the field. It will create a box around the field in the WPF client with the group name above.
The ‘Reference’ field is used if this field will act as a foreign key to another table. This includes user defined tables.
The various properties can be set on the field, e.g. ‘Read only’, ‘Delete’ etc.
- ‘Read only’ means that the field cannot be written to.
- ‘Delete’ means that the field is no longer used.
- ‘Mandatory’ means that the value of the field must be set before an entity can be created.
Furthermore, various SQL properties can be modified for the field as well.
Now click ‘Save’ to save the new user defined field.
Example
For this example, we will create a user defined field for ‘Inventory’ items, called ‘Rare’, using the specification beneath.
Click the ‘Generate C# class’ and pick ‘Client class’ from the drop down.
This gives me the following class:
public class InvItemClientUser : InvItemClient { public bool Rare { get { return this.GetUserFieldBoolean(0); } set { this.SetUserFieldBoolean(0, value); } } }
Now, simply paste this code into your project.
To use this new class, simply replace it with the use of InvItemClient. For example in this Execute method of a plugin:
public CrudAPI crud { get; set; } public ErrorCodes Execute(...) { var ruby = new InvItemClientUser { Item = "Ruby", Rare = true, CostPrice = 25000, }; return crud.Insert(ruby).Result; }
Now after running the above code. The Inventory item ‘Ruby’, has been inserted into my Inventory items as seen below.