Banana (Objects)

Documentation •
In this article

Banana is the namespace (object) through which all Banana script's methods, class and objects are accessible.

Banana Properties

Banana.application

The object Banana.application represents the running application.

Banana.console

The object Banana.console is used to send messages to the debug script.

Banana.Converter

The class Banana.Converter contains methods useful to convert data from and to various formats.

Banana.document

The object Banana.document represents the document currently open in the application. It contains base properties and methods, see Banana.Document (Base), and if the document represents an accounting document that contains additional accounting's properties and methods, see Banana.Document (Accounting). If any document is opened this object is of type Undefined.

Banana.IO

The class Banana.IO is used to read and write files.

Banana.Report

The class Banana.Report enables you to create reports, preview and print them in Banana Accounting.

Banana.script

The object Banana.script is used to get information about the running script.

Banana.SDecimal

The class Banana.SDecimal contains methods useful for decimal math calculation.

Banana.Test

The class Banana.Test contains methods to run test units.

Banana.Ui

The class Banana.Ui contains predefined dialogs to interact with the user, and methods to load dialogs from .ui or .qml files.

Banana.Xml

The class Banana.Xml contains methods to parse and access Xml data.

Banana Methods

Banana.compareVersion(v1, v2)

Compares two version strings. Version strings are in the form of "x.y.w.z". Returns 0 if v1 and v2 are equal, -1 if v2 is later and 1 if v1 is later.


var requiredVersion = "8.0.5";
if (Banana.compareVersion && Banana.compareVersion(Banana.application.version, requiredVersion) >= 0)
   Banana.Ui.showInformation("Message", "More recent or equal than version " + requiredVersion);
else
   Banana.Ui.showInformation("Message", "Older than version " + requiredVersion);

Banana.include(path)

The method Banana.include(path) includes a javascript file evaluating it.
If an error occurs, i.e. the file is not found or is not valid, the method throws an exception.

The path is relative to the current script being executed, if no protocol is specified. 

The application searches for include files in this order:
1) In the same directory as the current file.
2) In the directories of the currently opened include files, in the reverse order in which they were opened. 

If a protocol is defined, depending on the protocol, the path is relative to the main script's folder, the document's folder or the name of a document attacched to the current file.
- <relative_path_to_current_script>/<file_name>
- file:script/<relative_path_to_main_script>/<file_name>
- file:document/<relative_path_to_file>/<file_name>
- documents:<attachment_name>

Scripts included through the method Banana.include(path) can include other scripts through the method Banana.include(path), but not via the script's attibute @includejs. The method Banana.include(path) garantees that each distinct script is evaluated once, even if it is included more than one time from differents scripts. Path can contain ".." (parent folder), in the case the destination path is outside the main script's folder, the method will throw a security exception.


Banana.include("cashflowlib.js"); // a js file in the same folder
Banana.include("folder/cashflowlib.js"); // a js file in a subfolder
Banana.include("file:document/cashflowlib.js"); // a js file stored in the document table

 

Tell us how we can help you better
If the information on this page is not what you're looking for, is not clear enough, or is not up-to-date, let us know.

Share this article: Twitter | Facebook | LinkedIn | Email