En este artículo
Banana.Document is the interface to a document in Banana Accounting. The currently opened document can be accessed through the property Banana.document. A document can be also opened with the method Banana.application.openDocument.
Properties
cursor
Return a Cursor object with the current position of the cursor and the range of the selected rows.
var currentCursor = Banana.document.cursor;
locale
Return the locale of the document in the form of "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two- or three-letter ISO 3166 country code.
var locale = Banana.document.locale;
rounding
Return the rounding context of the current file that can be used with the SDecimal math functions.
var rounding = Banana.document.rounding;
tableNames
Return an array with the xml names of the tables in the document.
var tableNames = Banana.document.tableNames;
The tables in the document vary depending on the type of accounting. For example in a multi-currency accounting with VAT these are the tables:
- Accounts,Transactions,Budget,Totals,VatCodes,ExchangeRates,Items,Documents,FileInfo
uuid
Return the uuid (universally unique identifier) fo the document.
var uuid = Banana.document.uuid; // Ex.: "123e4567-e89b-12d3-a456-426652340000"
Methods
addMessage(msg[, idMsg])
Add the message msg to the document. The message is showed in the pane "Messages", and in a dialog if the application option "Show Messages" is turned on.
If idMsg is not empty, the help button calls an url with script's id and message's id (idMsg) as parameters.
See also: Application.AddMessage, Table.AddMessage, Row.AddMessage.
Banana.document.addMessage("Message text");
applyDocumentChange(docChange)
Apply a DocumentChange to the document. Returns true if the docChange has been applied, otherwise false.
A dialog showing the changes is showed to the user asking for confirmation.
var documentChange = {
"format": "documentChange",
//...
};
Banana.document.applyDocumentChange(documentChange);
clearMessages()
Clear all the document's messages showed in the pane "Messages".
Banana.document.clearMessages();
getMessages([tableName, rowNr])
Returns all messages showed in the pane "Messages", that refer to this document and optionally to given table and row number.
let msgs = Banana.application.getMessages();
for (let i = 0; i < msgs.length; ++i) {
let msg = msgs[i];
Banana.console.log("Error: " + msg.message);
}
The message object contains following properties:
- message: the message in the application language;
- referer: a string describing to which the message refer (usually the file name);
- level: the level of the message as string, can be one of "debug", "info", "warning", "debug";
- helpId: the help id of the message, used to link to the documentation;
- fileUuid: an id as string that uniquely identifies the file to which the message refer or empty;
- fileName: the file name that identifies the file to which the message refer or empty;
- tableName: the table name to which the message refer, or empty;
- rowNr: the row number as number to which the message refer, or -1;
- columnName: the column name to which the message refer to, or empty;
See also: Application.getMessages.
getScriptSettings()
Get the settings of the script saved in the document. You use this method to get settings that are private to the running script. It is possible to save the settings of the script through the method "setScriptSettings".
With this method Settings are saved and restored under the script id, If you change the script's id you will lose the saved settings.
Example:
// Initialise parameter
param = {
"searchText": "",
"matchCase": "false",
"wholeText": "false"
};
// Readscript settings
var strData = Banana.document.getScriptSettings();
if (strData.length > 0) {
var objData = JSON.parse(strData);
if (objData)
param = objData;
}
getScriptSettings(id)
Return the settings saved in the document under the id 'id'.
You use this method to get settings that are shared between scripts. As id we recommend to use a substring of the script's id. For example if you have the scripts 'ch.banana.vat.montlyreport' and 'ch.banana.vat.endofyearreport', then you can use as id 'ch.banana.vat'.
Example:
// Initialise parameter
param = {
"searchText": "",
"matchCase": "false",
"wholeText": "false"
};
// Readscript settings
var strData = Banana.document.getScriptSettings('ch.banana.vat');
if (strData.length > 0) {
var objData = JSON.parse(strData);
if (objData)
param = objData;
}
info(section, id)
Return the info value of the document referenced by section and id. Section and Id correspond to the xml name listed in the Info table, see command File info in menu "Tools" and set the view to complete to see the XML columns. If the value referenced by section and id doesn't exist, an object of type undefined is returned.
Example:
This is not an exhaustive list. For an exhaustive list run the command Menu Tools > File info, and switch to the view Complete.
// Get some value of the accounting file
var FileName = Banana.document.info("Base","FileName");
var DecimalsAmounts = Banana.document.info("Base","DecimalsAmounts");
var HeaderLeft = Banana.document.info("Base","HeaderLeft");
var HeaderRight = Banana.document.info("Base","HeaderRight");
var BasicCurrency = Banana.document.info("AccountingDataBase","BasicCurrency");
// For openingDate and closureDate use instead startDate and endDate
var openingDate = Banana.document.info("AccountingDataBase","OpeningDate");
var closureDate = Banana.document.info("AccountingDataBase","ClosureDate");
// For file accounting type
var FileType = Banana.document.info("Base","FileType");
var FileGroup = Banana.document.info("Base","FileTypeGroup");
var FileNumber = Banana.document.info("Base","FileTypeNumber");
// For customer settings
var customersGroup = Banana.document.info("AccountingDataBase","CustomersGroup");
var suppliersGroup = Banana.document.info("AccountingDataBase","SuppliersGroup");
FileTypeGroup / FileTypeNumber combinations:
- 100 Double entry accounting
- 100 No VAT
- 110 With VAT
- 120 Multi Currency
- 130 Multi Currency with VAT
- 110 Income and Expense accounting
- 100 No VAT
- 110 With VAT
- 130 Cash Book
- 100 No VAT
- 110 With VAT
- 400 Address / Labels
- 110 Labels
- 120 Address
scriptSaveSettings(string)
Save the settings of the script in the document. The next time the script is run, it is possible to read the saved settings with "scriptReadSettings".
With this method Settings are saved and restored under the script id, If you change the script's id you will lose the saved settings.
Example:
// Save script settings
var paramString = JSON.stringify(param);
var value = Banana.document.scriptSaveSettings(paramString);
Deprecated. Use setScriptSettings instead.
scriptReadSettings()
Return the saved settings of the script.
With this method Settings are saved and restored under the script id, If you change the script's id you will lose the saved settings.
Example:
// Initialise parameter
param = {
"searchText": "",
"matchCase": "false",
"wholeText": "false"
};
// Readscript settings
var strData = Banana.document.scriptReadSettings();
if (strData.length > 0) {
var objData = JSON.parse(strData);
if (objData)
param = objData;
}
Deprecated. Use getScriptSettings instead.
setScriptSettings(value)
Save the settings of the script in the document. It is possible to read the saved settings of the script with the method "getScriptSettings".
With this method Settings are saved and restored under the script id, If you change the script's id you will lose the saved settings.
Example:
// Save script settings
var paramString = JSON.stringify(param);
var value = Banana.document.setScriptSettings(paramString);
setScriptSettings(id, value)
Save the settings in the document under the id 'id'. It is possible to read the saved settings with "getScriptSettings(id)".
You use this method to set settings that are shared between scripts. As id we recommend to use a substring of the script's id. For example if you have the scripts 'ch.banana.vat.montlyreport' and 'ch.banana.vat.endofyearreport', then you can use as id 'ch.banana.vat'.
Example:
// Save script settings
var paramString = JSON.stringify(param);
var value = Banana.document.setScriptSettings('ch.banana.vat', paramString);
table(xmlTableName)
Return the table referenced by the name xmlTableName as a Table object, or undefined if it doesn't exist.
Banana.document.table("Accounts");
table(xmlTableName, xmlListName)
Return the table referenced by the name xmlTableName with the rows of the list xmlListName as a Table object, or undefined if the table or the list don't exist. The default list is the 'Data' list.
Banana.document.table("Transactions", "Examples");
Banana.document.table("Transactions").list("Examples"); // alternative way
See also: Table.list, Table.listNames.
value(tableName, rowNr, columnName)
Return the value in table tableName, row rowNr and column columnName as string. If the table, row or column are not found, it returns an object of type undefined.
Banana.document.value("Accounts", 5, "Description")