In Uniconta, you can change data in several places using small scripts, pieces of code.
You can use these scripts in data manipulation, calculated fields, data import and assign new field values.
You can use "Uniconta script" which is a proprietary language that can be used to write simple formulas. If you want to use C# code, this is also an option, simply select this when creating the script.
The C# field is checked. The code will then be compiled with the built-in C# compiler and .Net code will be executed. This gives you access to the entire large program library to manipulate data or display calculated fields.

Examples in C#
In order to update your data using C# code, you need the following settings. In Field name, select the field you want to change. In order to write code, select"Script" (This applies in "Assign new field value") If you want to write C#, check the"C#" box In the"Script" field, you can now write the desired code. REMEMBER: Set the desired filter before updating all data.
Replace one text with another
Above is an example of how to change a year on a project name to a new year via "Assign new field value". The project name contains a year and via "Assign new field value" you can replace a specific value with another. Here a year, 2021 is replaced with 2022.rec.Number.Replace("2021", "2022");The examples below also use rec.Number which is the project number field //Replace one value with another
rec.Number.Replace("2020", "2021");//Replace a value with a nothing
rec.Number.Replace("2020", "");
Find a value in a text string
//Find the value in the string from 0 to the 3rd character, (the first three characters) rec.Number = "10501-2022"rec.Number.Substring(0, 3);Result="105" //Find the value in the string from the 2nd character and 3 characters forward rec.Number = "10501-2022"
rec.Number.Substring(2, 3);Result="501"
Change date values with year
rec.Date = rec.Date.AddYears(1);
Change date values with number of days
Here 210 days are added to an existing date. I.e. 7 approx. months rec.Date = rec.Date.AddDays(210);Insert today's date
If you want to insert the current date, you can type: DateTime.Now.ToString("dd-MM-yyyy"); The format of the date can be varied. The above is day-month-year. Below are a few examples, and if you want more, you can search C# manuals for DateTime. 21-10-2023, written "dd-MM-yyyy" 21/10-2023, written "dd/MM-yyyy" October 21, 2023, written "dd. MMMM yyyy"DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss");
Here are a few examples from the chart of accounts
//Replace a character at a specific position //Remove the first character in a string, e.g. 0 in front of account no. 01001 rec.Account = "01001";rec.Account.Substring(1, 4);Result = "1001" //Add a value in front rec.Account = "1001";
"0"+rec.Account;Result = "01001" //Add a value behind it rec.Account = "1001";
rec.Account+"0";Result = "10010" //Fine the length of a text dash rec.Account = "101001";
rec.Account.Length;Result = 6
Round three, or more, decimal places to two
Math.Round([value], [number of decimal places], [rounding option]) rec.SalesPrice3 = 150.345; // Rounds downMath.Round(rec.SalesPrice3, 2, MidpointRounding.ToEven);Result = 150.34 //Runder on
Math.Round(rec.SalesPrice3, 2, MidpointRounding.AwayFromZero);Result = 150,35
Rounding of numbers and sales prices to the nearest 0.25 cents
rec.SalesPrice1 = 150.345; //Rounding of sales price1 to the nearest 0.25 centsMath.Round((rec.SalesPrice1)/25, 2, MidpointRounding.AwayFromZero)*25;Result = 150,25 //Rounding of sales price1 to the nearest 0.25 cents
Math.Round((rec.SalesPrice1)/25, 2, MidpointRounding.AwayFromZero)*25;Result = 150,50
Date format to text format
// If you want a date value from a date field inserted into a text field, you can convert a date format from date to string with the code below // conversion to only one daterec.Date.ToString("dd-MM-yyyy")//Convert to date and time
rec.Date.ToString("dd-MM-yyyy HH:mm:ss")
Text format to number format
//Converting a text to numbers.Convert.ToDouble(rec.InvItem.TariffNumber) * rec.Qty;
Rounding of numbers and sales prices to the nearest 0.25 cents
//Rounding of sales price1 to the nearest 0.25 centsMath.Round((rec.SalesPrice3)/25, 2, MidpointRounding.AwayFromZero)*25;
Examples without using C#
Calculation methods Here you can see the basic calculation methods.- + (Addition)
- - (Subtraction)
- * (Multiplication)
- / (Division)
- % (Modulus)
- - (Unary Minus)
- 5 + 10 * 2 // (equals 25)
- (5 + 10) * -2 // (equals -30)
- 6 * 5 - 2 / 2 // (equals 29)
- 6 * (5 - 2) / 2 // (equals 9)
- Direct (=)
- Via multiplication (+=)
- Via subtraction (-=)
- Count = 10; // Counter set to 10
- Count += 1; // Counter is increment by 1 and becomes 11
- Total += Amount; // Amount is added to the Total
Mathematical operations
- and (&&)
- or (||)
- xor (^)
- == // equal
- != // not equal
- > // greater than
- >= // greater or equal than
- < // less than
- <= // less or equal than
- (5 > 3) // true
- (5 + 4 >= 3* 4) // false
- (Count > 0 and Aborted != 0)
- (Total != MaxValue or Total * 100 / SumOfAll >= 50)