Build your first Extension

在此文中

Introduction

This walkthrough provides step-by-step guidance for creating a simple BananaApp that uses JavaScript API to interact with Banana Accounting software.

The “Hello World!” program is a classic tradition in computer programming. It is a short and complete first program for beginners, and it is perfect as first BananaApp example.

There are three basic steps in order to experiment with BananaApps:

  1. Create the JavaScript file
  2. Install the BananaApp
  3. Run the BananaApp

Create the JavaScript file

  1. Use a text editor. Download a text editor from your choice (Notepad++, Sublime Text, etc.) that will let you code in a simple way.
    It is important to be sure you can save with the UTF-8 encoding.

  2. Copy the following JavaScript code and paste it on your text editor.

    
    // @id = ch.banana.app.helloworldexample
    // @api = 1.0
    // @pubdate = 2018-10-24
    // @publisher = Banana.ch SA
    // @description = BananaApp example: Hello world
    // @task = app.command
    // @doctype = *.*
    // @docproperties =
    // @outputformat = none
    // @inputdataform = none
    // @timeout = -1
    function exec() {
       //Create the report
       var report = Banana.Report.newReport("Report title");
       
       //Add a paragraph with the "hello world" text
       report.addParagraph("Hello World!");
       
       //Print the report
       var stylesheet = Banana.Report.newStyleSheet();
       Banana.Report.preview(report, stylesheet);
    }
  3. Change the attributes of the BananaApp (for more information, see Apps attributes):
    • @id = <your_script_id>
      This is the identification of the script.
      In order to avoid duplicates, it is important to assign a unique id at avery script.
    • @description = <your_script_description>
      This is the name of the BananaApp. The text will be displayed in the dialogs.
  4. Save the file as helloworld.js.

You have now created your first BananaApp!

Install the Extension

What next? The next step is to install your Extension into the Banana Accounting software.
Before to use the Extension , and see the "Hello World!" text displayed as report in Banana, the App needs to be installed.
So, let's see how to install the "Hello World!" Extension.

  • Open an accounting file in Banana Accounting
  • In Banana select from the menu Apps the command Manage Apps...
  • Click on Add from file...

     
  • Select the helloworld.js file.
  • Click on Open to install the App.
  • The Extension is displayed in the dialog.
    By Selecting Installed from the left, all the installed Extensions (both local and online apps) will be displayed.


     
  • Click on Close to close the Manage Banana Apps dialog

You have now installed the Extension!

Important:

  • Once installed, the JavaScript file needs to always remain in the same directory.
  • If the JavaScript file is modified, the program will always use the last version.

Run the Extension

Finally, now it is possible to run the "Hello World!" Extension and see the results.
To run the app:

  • In Banana select from the menu Apps the Example Hello World app.


     
  • The app is executed and returns the following reports

 

Congratulations, you have now created, installed and executed your own BananaApp!

Uninstall the Extension

In case you don't need an installed Extension anymore, it is also possible to remove it from Banana Accounting software using the uninstall command.

  • In Banana select from the menu Apps the command Manage Apps...
  • Select the Installed section on the left in order to display all the currently installed Extensions.
  • Select the Extensions you want to remove and click Uninstall.


     
  • Confirm with Ok to remove the App from Banana Accounting software.


     

The Extension is now removed from Banana Accounting software, but the JavaScript file (i.e. helloworld.js) is not removed from you computer.

More about Extensions

 

 

 

 

This documentation is outdated

The most complete and up-to-date documentation is the one of Banana Accounting Plus: Try it now

分享这篇文章: Twitter | Facebook | LinkedIn | Email