Sunday, 9 January 2011

Beginners Guide to QlikView Extension Objects : Part 1

I thought that I might write a quick guide to creating an extension objects for QlikView 10.

What is an extension object?  Well, it allows us to create a chart using html and javascript or consume a 3rd party flash/silverlight object.  Our chart can use data from QlikView and it can pass click events back to QlikView.  Basically, we can create any chart that we want that doesn’t exist already.

You might think that there would be a whole lot of work to do to create this, but it is actually really simple to get a chart up and running and consuming QlikView data.

Extension objects live in the C:\Users\your.username\AppData\Local\QlikTech\QlikView\Extensions\Objects folder for desktop users.  Each extension must have a folder for itself.  However, you can have multiple sub-folder levels if you want.

The first thing that I will do in the Objects folder is create a sub-folder for my company’s extensions.  My company is Capricorn Ventis Ltd. so I will create a folder called CVL.  In this folder, I will create a sub-folder for each extension.  First one that I am going to create is HelloWorld (doesn’t every example have to start with a Hello World!).  Now, under the Objects folder, I have CVL\HelloWorld.

Every extension has a minimum of 1 file associated with it - Definition.xml.  This file will define the element, ExtensionObject (which can have other sub elements to, for example, set some default values):

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject />

That’s it – simple.  We will have a look at some additional options for this file in the next part.

With this one file in the HelloWorld folder, I can now see in QlikView (in Web View mode) when I right-click and select New Sheet Object, Extension Objects, I will see my new CVL/HelloWorld object (with no icon) which I can drag onto the sheet and it will create an object.  It won’t be a very awe inspiring object (a blank box) but you can set properties (such as caption) just as you would for other charts.

We need to add a couple of things to make this just a little more advanced.  First, if we want to have an icon (and you really should), we need to add a 24x24 PNG file called icon.PNG to the folder – any design that you want.  Next, I am going to make a small modification to the Definition.xml file:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionObject  Label="CVL Hello World" />

This label will be what is displayed in the New Sheet Object dialog – next to the icon defined by the PNG file.

Now that those aesthetics are sorted out, we can make the object actually do something.  We need to add a JavaScript file that will define the code that will be run by this object.  The file is always called script.js.  This js file must define a call to Qva.AddExtension which defines a name and function that will be called when the extension loads:

Qva.AddExtension('CVL/HelloWorld', function() {
   // Set the HTML
   this.Element.innerHTML = "<h1>Hello World</h1>";
},true);

Note that the name defined in AddExtension is the same as the path to the folder as it would be from the Objects folder.  This is required.

This code is very simple – it just outputs some simple html – but it reveals how we can do some much more advanced stuff.  If we can generate html, we can output it to our application and do so much!  All we need now is some data.

In the next part, I will show you how to consume QlikView data.

15 comments:

  1. Hi Stephen,

    Very nice and useful post.

    i was following your above post to create my 1st extension chart.i`m getting the Extension object on Qv but when i tried to drag the object in Qv it is throwing me the following error. Pl help me to debug this error.

    "An Erro has occured in the script on this page

    Line: 3033
    Char: 16
    Error: 'Qva.Mgr[...]prototype' is null or not an object
    Code: 0
    URL: http://qlikview/QvQjaxZfc/QvAjax.js

    Do You want to continue running Script on this page?"

    ReplyDelete
    Replies
    1. Hi Shridhar,

      You probably have the subfolder and name of your extension wrong in your script.js file:

      Qva.AddExtension('SubFolder/ExtensionName', function() {
      ....
      }

      It should be the same as the location of the extension within the $APPDATA/QlikTech/Extensions folder.

      Delete
  2. What does the boolean parameter at the end of the
    Qva.AddExtension(name, function, true) means? I've seen examples with both values but cant figure out the difference..

    ReplyDelete
  3. Hi Stephen...
    Can I do this example in QlikView Trial version?
    Why I am asking this,there is no such folder named QlikTech in my system.I could found the path upto D:\Users\Rams\AppData in my system,and there is no Local folder.Presently I am using trial version.

    ReplyDelete
  4. Hi,

    Local is a Windows default folder, not a QlikView one so the folders may be hidden. Change your settings to show hidden folders.

    It should work fine in Personal Edition. PE is a fully functioning version of QlikView - the only restriction is on the QVWs that you create with it.


    Stephen

    ReplyDelete
  5. Hi Stephen,
    Thanks for your quick reply. I have changed my settings as you told.Now that folder is visible .But,I have a small doubt,I have installed QV in 'D' drive,but my OS is in 'C' drive.I could find Local\QlikTech\QlikView in 'C' drive. If I create Extension object there,does it work?

    Thanks,
    Rams

    ReplyDelete
  6. Hi,

    Again, the Local is a Windows folder so it shouldn't matter where QlikView is installed.


    Stephen

    ReplyDelete
  7. And there are no Extensions\Objects folders.Shall I need to create those folder in QlikView folder?.
    If you dont mind can I ask one question which is out of this context?
    How to create web application from QlikView.I have seen that we can change to Desktop View to WebView vice versa.
    But,how to create url, I mean how to run that application in browser.
    I am new to QlikView, plase help me.....

    ReplyDelete
  8. Hi Rams,

    If you have a QlikView server then you can deploy your QVW there and it can be connected to via web (or thicker clients). The "Web View" is just to show you how it will look once deployed.

    Regards,


    Stephen

    ReplyDelete
    Replies
    1. Hello Stephen, i'm using Org Chart in my application but the chart is not visible in the browser. Plz help

      Delete
  9. Thank you very much for this tutorial!! It was VERY helpful for me.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. After BDWT I got inspired learning about extensions. Feels like this was a great place to start. Well written, easy to understand. Now I just have to set aside some hours for the actual hands on experience. I wo.t become a good QlikView Extension JavaScript developer by only reading about it on your blog.

    Cheers
    Vegar

    ReplyDelete