The budget line script is invoked for each bookkeeping line of the selected dossiers, with some predefined variables that contain the bookkeeping data to be evaluated. The goal is to return 2 variables that indicate where the amount must be placed in the budget (or not): schemaCode and dimensionCode.
The variable excluded can be set to true to indicate that the line should be excluded from processing.
Variable name | Description |
---|---|
excluded | This indicates if the line should be excluded from processing. Defaults to false and can be set to true. |
amount | This is the amount of the line.Note: you can change the amount in the script. |
lineNb | This is the line number |
lineRef | This is the line reference |
dossierRef | This is the code of the bookkeeping dossier |
docNb | This is the document number |
journalCode | This is the journal code |
bkAccount | This is the bookkeeping account code |
anAccount1 | This is the analytic account code, of level 1 |
anAccount2 | This is the analytic account code, of level 2 |
anAccount3 | This is the analytic account code, of level 3 |
anAccount4 | This is the analytic account code, of level 4 |
anAccount5 | This is the analytic account code, of level 5 |
anAccount6 | This is the analytic account code, of level 6 |
relationCode | This is the relation code |
schemaCode | This is the initialized schema code. Set this to undefined to add this line to the unassigned amounts. |
dimensionCode | This is the initialized dimension code. Set this to undefined to add this line to the unassigned amounts. |
The following code excludes all journals except those with the code 'AK1', 'VK1' and 'DIV1':
if (journalCode != 'AK1' && journalCode != 'VK1' && journalCode != 'DIV1') { // journalCode is not in list, exclude line excluded = true; return; }
The following code evaluates the bookkeeping account number and determines the schema code based on that In this example, accounts with number between 600000 and 610000 get the schema code 'GDS', accounts with
number between 610000 and 620000 get the schema code 'SVC' and the others get the schema code 'OTH':
if (bkAccount >= 600000 && bkAccount < 610000) { schemaCode = 'GDS'; } else if (bkAccount >= 610000 && bkAccount < 620000) { schemaCode = 'SVC'; } else { schemaCode = 'OTH'; }
In the following example, the code fetches the schema and dimension code from the line reference, using a regular expression. The line references must contain a code of 'PR', followed by 4 alphanumeric characters representing the
schema code and ending with 3 numeric characters representing the dimension code. E.g. a line reference containing 'PRBOOK101' would mean schema code 'BOOK' and dimension code '101'.
var rg = /PR(\w{4})(\d{3})/i; var m = rg.exec(lineRef); if (m != null) { schemaCode = m[1]; dimensionCode = m[2]; }Regular expressions are a very powerful feature for text parsing and extraction. Refer to the 'Useful links' section at the bottom of this page to know more.
The following code only includes the document 100 from journal 'AKP':
if (journalCode != 'AKP' && docNb != '100') { excluded = true; return; }
For general reference, the Mozilla Developer Network is very extensive and well-documented.
To start using operators (like +, ++, =, ==,...), refer to: JavaScript operators
To start using if
constructions, refer to: if statement
To start using for
loops, refer to: for loop
To know more about regular expressions, refer to: regular expressions on MDN.