JavaScript

In addition to use of Plugins, jGnash allows you to create and run JavaScript programs. The internals of the jGnash engine and some user interface functions can be accessed to create custom reports, create and modify transactions, etc.

Running a JavaScript program is as simple as using ToolsRun JavaScript command from the menu bar.

Below is an example JavaScript program that displays the accounts in the currently loaded file and demonstrates how to display a simple dialog. To try the program, create a text file using your favorite editor with a name of your choice that ends with a .js extension. After creating the file, simply using the ToolsRun JavaScript command to select the program and run it.

importPackage(javax.swing);
                importPackage(Packages.jgnash.ui);
                importPackage(Packages.jgnash.engine);

                // helper function to print messages to the console
                function debug(message) {
                java.lang.System.out.println(message);
                }

                // show the console dialog to see the debug information
                ConsoleDialog.show();

                // this is how to get the default Engine instance
                var engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

                // get a list of accounts
                var accountList = engine.getAccountList();

                // loop and print the account names to the console
                for (i = 0; i < accountList.size(); i++)
                {
                var account = accountList.get(i);
                debug(account.getName());
                }

                // just to show how to use Swing
                var optionPane = JOptionPane.showMessageDialog(null, 'Hello, world!');
            

JavaScript programs have the advantage of not requiring the use of an IDE or Java compiler to create and test a program. The disadvantage is troubleshooting syntax and logic errors can be more difficult than writing a jGnash Plugin.