Include JavaScript Library in your Intrexx Application

As most of the people I also don’t like to reinvent the wheel. This is why, when I have to code something, I try to use existing, usually even free, code libraries to work with. Since most of them are also open source, I can be pretty sure they are of high quality and used and tested very often.

In Intrexx you can include two types of external libraries. Java libraries as well as JavaScript libraries. In this post I will show you how to include a JavaScript library in Intrexx and how to include the library in the application package, so that it will be exported and later imported together with the rest of the package.

Download or Create a Library

First of all we need an existing library to start with. I’m going to introduce several JavaScript libraries in later posts. That’s why for now I use a JavaScript of my own, to show you how including an external- library in your Intrexx application works.

So this is the script myExternalLibrary.js

function myExternalHelloWord(){
    alert("Hello from the outside!");
    return true;
}

Find a location

The JavaScript file needs to be accessible from the browser. This means any JavaScript files need to be placed underneath in the portals /external/htmlroot/ directory. Custom JavaScript files are usually placed in the /external/htmlroot/includes/custom folder. This way they are available to multiple applications and can be found and maintained more easily. If the JavaScript files are shipped with an application, they automatically will be placed under the /external/htmlroot/include/<application-guid> folder.

Add the library to your application-package

If you want to ship the library with your application, Intrexx offers the possibility to add it to your application-package. To achieve this, simply add the JavaScript file to the application from within the application designer. You can do this by opening the details-page of your application. On the bottom of the first tab there is the Link Open temporary working directory. This link opens an explorer-window with the applications file structure in it. Here you can add the JavaScript file to the “include” folder. After publishing the application the file will be automatically added to the folder /external/htmlroot/include/<application-guid>.

Include the library in your application’s JavaScript

Since the file is available , let’s include it in an application JavaScript.

First the browser needs to load the library’s JavaScript file. Intrexx offers a method in its own API to do this. This method is also part of the Intrexx JavaScript snippet-library, inside the JavaScript editor. After loading your JavaScript file, methods of the library can already be called.

function loadAndCallExternalFunction(){
	Loader.loadJsFileOnDemand("./include/<application-guid>/myExternalLibrary.js");
	myExternalHelloWord();
	return true;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.