Write budget global scripts

The budget global script is executed once all individual bookkeeping lines were processed, but before the budgetting data is added.
This script can be used to modify or move amounts in the analysis sheet.

In the script, you can use the analysis object to change amounts or to get a list of lines.

The analysis object

Name Description
analysis.getAmount(<schema code>,<dimension code>) Get the (sum of) amounts on the specified intersection of schema and dimension. Both parameters can be omitted (pass null instead of a value)
analysis.addAmount(<schema code>,<dimension code>,<amount>) Sets an amount on the specified intersection of schema and dimension.
analysis.changeAmount(<source schema code>,< source dimension code>,<target schema code>,< target dimension code>,<ratio>) Moves (part of) an amount from the source intersection of schema and dimension, to the target intersection of schema and dimension. The ratio parameter is a percentage expressed as a float value between 0 and 1.
If <source schema code> and < source dimension code> are equal to <target schema code> and < target dimension code>, there isn't an actual move but the amounts will be modified in-place.
analysis.getLines([schemaCode], [dimensionCode]) Retrieves a list of all the lines contained in the current process. You can iterate of these line objects, change the schema and dimension codes and/or change the amount.
The schemaCode and dimensionCode are optional, and allow to retrieve all the lines for a given schema/dimension combination. Note that when provided, they both must be provided (not only the schema- or dimensioncode).
You can't use the list to add new lines: the add new amounts use the addAmount method or the copyLine method.
analysis.copyLine(line) Copies a given line (initially retrieved via the getLines method) and adds it immediately to the list of lines in the analysis.
See below for an example.

The line object

The line objects are retrieved via the budget.getLines method. Most properties of the line object are read-only although you can modify the schema code, the dimension code and the amount.

Property Description
schemaCode This is the initialized schema code. Note: you can change the amount in the script.
dimensionCode This is the initialized dimension code. Note: you can change the amount in the script.
amount This is the amount of the line. Note: you can change the amount in the script.
lineRef This is the line reference. Read-only.
journalCode This is the journal code. Read-only.
bkAccount This is the bookkeeping account code. Read-only.
anAccount This is the analytic account code. Read-only.
relationCode This is the relation code. Read-only.
date This is the document date. Read-only.

Scripting examples

Distributing amounts (using the changeAmount method)

The following code moves 30% of the amount on the intersection of '1300' and 'BE' to the intersection of '1400' and 'FR':

        analysis.changeAmount('1300','BE','1400','FR',0.3);
Distributing amounts (using the getLines method)

The following code moves 30% of the amount on the intersection of '1300' and 'BE' to the intersection of '1400' and 'FR'.
The result is the same as in the previous example, except that we're using the individual lines here instead:

        var sum = 0;
        var lines = analysis.getLines();// the 'lines' variable contains all processed lines
        for (var i = 0; i < lines.length; i++) {
            if (lines[i].schemaCode == '[1300]' && lines[i].dimensionCode == '[BE]') {
                sum += lines[i].amount;
                lines[i].amount = lines[i].amount * 0.7;
            }
        }
        analysis.addAmount('1400','FR', sum * 0.3);
Moving amounts based on the bookkeeping account

The following code moves all amounts that were placed on accounts 611000 through 611999 on schema 'GENCOST' and dimension 'TAX'.
This code must use the line objects because these have a property referencing the bookkeeping account number:

        var sum = 0;
        var lines = analysis.getLines();// the 'lines' variable contains all processed lines
        for (var i = 0; i < lines.length; i++) {
            if (lines[i].bkAccount >= 611000 && lines[i].bkAccount < 612000) {
                sum += lines[i].amount;
                lines[i].amount = 0;    // clear amount
            }
        }
        analysis.addAmount('GENCOST','TAX', sum);
Copying and modifying a line

The following code copies a line retrieved with the getLines method, changes the schemaCode to 'GENCOST' and halves the amount.

        var lines = analysis.getLines();// the 'lines' variable now contains all processed lines
        var line = lines[0];// take first line of list (this is an example, in production: check that there are lines in list)
        var copy = analysis.copyLine(line);// copies the line and adds the copy to the analysis
        copy.amount = line.amount * 0.5;
        copy.schemaCode = 'GENCOST';
To Top