Under Tools you will find the
Table Trigger menu.
Table trigger is used to create small pieces of code that can automate small jobs on the tables/files in Uniconta.
All support regarding triggers is payable support. If you have created triggers on your accounts and they create challenges for the accounts, this will be payable support if you contact support.
The examples in this article are indicative and work in a standard Uniconta accounting system. It is your own responsibility to use them and should be tested in a test environment before coding them into an operating environment.
Tips:
The value of a custom
fldNote field is called as follows:
rec.Debtor.GetUserFieldString("fldNotat")
To set a value for a custom field,
fldNotat, type the following:
rec.SetUserFieldString("fldNotat", "Dette er vores notat til feltet");
It is possible to create a message box, for example if a field is not filled in. A message box can be written as follows:
System.Windows.Forms.MessageBox.Show("OnUpdate");
Example 1 - Choose a layout based on employee:
When a specific employee creates a sales order, that employee must use a specific layout.
You can force this by creating a trigger.
Go to Tools/Table Trigger
Here you select the directory on which you want to perform a trigger. To find the directory, go to the desired location in Uniconta and press F12.
If it is a sales order that needs to be activated with a code, select "DebtorOrderClient"
Then you select "Trigger", i.e. when this code should be activated.
In the example, OnInsert is selected
If you can program in C#, check the C# box
In the Script field, you are now ready to code.
/* Hvis medarbejderen er 1007, så skal layoutgruppen sættes til England */
if (rec.Employee=="1007")
rec.LayoutGroup = "England";
/* Hvis leveringsdato på en salgsordre skal være dags-dato */
rec.DeliveryDate =DateTime.Today;
Click save and test your trigger on the sales order.
Example 2 - Auto-fill purchase invoice number with any number:
This can be used for testing if you often test purchases or simply need a random invoice number on a purchase invoice.
Via a trigger, you can save a number in the Invoice no. field when exiting the purchase screen.
In the example, the current date with time, including seconds, is selected for the invoice number, so it will never be the same.
Here's what you do:
Create a trigger:
Go to Tools
Select Table trigger
Select the CreditorOrderClient table
Click on Table trigger in the menu
You can just add a trigger when you create an order, but it's also a good idea to add a trigger when you change an order.
Create an invoice number for a new purchase order:
Add a table trigger
Set Trigger to OnInsert
Check the box in C#
Paste the following code in the Script field:
rec.InvoiceNumber = DateTime.Now.ToString("MMddyyyyHHmmss");
(Replace " with new " if necessary, as they may be changed in the copying process!)
Click Check. If you get OK, all is well - if you get an error, with a lot of code, start replacing " and try checking again.
Save and try to create a purchase order.
The trigger should look like this:

If you want the same functionality for already created purchase orders, you need to create a second trigger.
Create an invoice number for an existing purchase order:
Add another table trigger on CreditorOrderClient
Set Trigger to OnUpdate
Check the box in C#
Paste the following code in the Script field:
if (rec.InvoiceNumber=="0" || string.IsNullOrEmpty(rec.InvoiceNumber) ) {
rec.InvoiceNumber = DateTime.Now.ToString("MMddyyyyHHmmss");
}
(Replace " with new " if necessary, as they may be changed in the copying process!)
Click on Check. If you get OK, all is well - if you get an error, with a lot of code, start by replacing " and try checking again.
Save and try to change a purchase order that does not have an invoice number.
The trigger should look like this:
Example 3 - Auto-fill project name with debtor name:
From the
Debtor/Debtor overview, you can create a project on the selected debtor on the menu ribbon (if the project module is enabled).
Via a trigger, you can have the project name filled with the debtor's name automatically during creation.
Create the trigger:
Go to Tools
Select Table trigger
Select the ProjectClient table
Click "Add table trigger" in the menu
Set Trigger to PageLoad
Paste the following code in the Script field:
if (rec.Name==null) {
rec.Name = rec.DebtorName;
}
(Replace "with new" if necessary, as they may be changed in the copying process!)
The trigger should look like this:
Example 4 - Set payment method to X if account = X in accounting journal:
If you have a debtor/creditor/finance account that, for example, needs a specific payment method for each posting, you can use this trigger.
Create the trigger:
Go to Tools
Select Table trigger
Select the GLDailyJournalLineClient table
Click "Add table trigger" in the menu
Set Trigger to OnUpdate
Check the box in C#
Paste the following code in the Script field:
if (rec.Account=="X")
rec.PaymentMethod = "X";
// Erstat X med kontonavn samt den ønskede betalingsmetode.
// Betalingsmåder: "Kreditors Bankkonto", "IBAN", "+71", "+73", "+75", "+04", "Ingen".
Click Check. If you get OK, all is well - if you get an error, with a lot of code, start by replacing the symbols
" and try checking again.
The trigger should look like this:
Possibilities with Triggers
A trigger can be activated on 8 different methods, and only once per method, per table. So if you want to have multiple functions on the same method, these must be created under one.
You cannot change a trigger from one method to another. You have to create a new one and delete the trigger you are not using.
Trigger |
Trigger description |
Init |
Init can be used to define a parameter before the screen is loaded. |
PageClosed |
PageClosed runs when you close a screenshot. |
PageLoad |
PageLoad runs when you open a screen.
For example, you can insert data in advance when creating a new sales order, project or item. |
OnEnter |
OnEnter runs when you are standing on the field you have made a trigger on. |
OnLeave |
OnLeave runs when you leave the field you have made a trigger on.OnDelete |
OnDelete |
OnDelete runs when you delete data from the field you have created a trigger on.
For example, you can document the time of data deletion. |
OnInsert |
OnInsert runs when you create/insert data.
For example, when creating a sales order or a new debtor/creditor. |
OnUpdate |
OnUpdate runs when you update existing data in the trigger field.
For example, if value X = X in field A, insert value Y in field B.
You can also use OnUpdate to register when changes were last made to a debtor or an item. |