OK, it’s now time to stop with theory and start coding. We’ll create our first “Hello World” extension.
The easiest way to start with your first QlikView Extension is to create the required extension code where QlikView expects extensions to be:
In Windows 7/8 QlikView is loading extensions from the following folder:
C:\Users\%USER%\AppData\Local\QlikTech\QlikView\Extensions\Objects
Step 1 – Creating the Necessary Files
- First create a folder named “ET-HelloWorld” (ET stands for Extension Tutorial).
C:\Users\%USER%\AppData\Local\QlikTech\QlikView\Extensions\Objects\ET-HelloWorld
- Create two empty files within this folder, one called “Definition.xml” the other “Script.js”
The Definition.xml
file is the main file where QlikView searches for some meta-information of your QlikView extension. We start with a basic set of information:
<?xml version="1.0" encoding="utf-8" ?> <ExtensionObject Path="ET-HelloWorld" Label="Hello World" Description="Hello World Extension" Type="object"> </ExtensionObject>
If QlikView loads this file the following information is set:
- The path (folder) of our extension is set to “ET-HelloWorld”.
- Label and Description is set to “Hello World” and “Hello World Extension”, we will recognize these values in a few minutes when we are adding the extension to a QlikView Document.
- Finally we have defined that we are aiming to create an Object Extension by setting the “Type” attribute to “object”.
Now open the Script.js
file and type/paste the following code into it:
Qv.AddExtension("ET-HelloWorld", function () { // Set the extension object's inner Html this.Element.innerHTML = 'Hello World'; });
If this piece of code is loaded by QlikView an extension will be made available in QlikView Desktop and the inner Html of the extension element will be filled with “Hello World”.
Test Your Hello World Extension
Now let’s add the newly created extension to a new QlikView Document:
- Open QlikView Desktop
- Create a new QlikView document and save it
- Switch to WebView
- Click somewhere in the sheet and activate the context-menu (right mouse click)
- Navigate to “New Sheet Object”
- Switch to the accordion panel “Extension Objects”
- You should now see a window very similar as the one below with at least having your “Hello World” extension in the list of available objects:
- Drag & Drop the “Hello World” extension somewhere to your sheet.
- You will see the result of your “Hello World” extension:
Congratulations, you have created your first QlikView Object Extension!
The Anatomy of a QlikView Extension
It’s now time to understand the anatomy of a QlikView extension. There are at least, as you have realized in your Hello-World example, two files required for an extension to work property:
- Definition.xml
- Script.js
But there are other files too, so here’s the list of all possible elements of an extension:
File Name | Description |
---|---|
Definition.xml |
Within the Definition.xml file some meta-data (like the name of the extension, a description, etc.) and all properties and initial values for the extension are defined.
|
Script.js |
The Script.js file is the main entry point for your extension, QlikView is loading the extension only if a Script.js can be found and is a function called Qv.AddExtension within this file.
|
Icon.png |
By adding a file called Icon.png to the directory you can define the icon shown in the list of all extensions.This should be a PNG-file with 24×24 pixels. |
.qvpp files | QlikView Property Pages, you’ll learn more how to use this functionality in some of the following chapters. |
Additional files | Additional resource files like JavaScript files, images, etc. – you’ll learn more how to reference these files in one of the following chapters. |
In the next chapter we’ll concentrate on improving the experience of our Hello-World example.
5 Comments