Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

zadravecm
New Contributor II

Qlik Sense Extensions : bring other js files in

Hi,

I am making some Qlik Sense extension, and I would like to use external .js files.

I was looking to a Qlik Sense documentation page and tutorial, and I don't know what I am doing wrong.

main.js

define( [

        'jquery',

        'qlik',

        './scripts/test',

        'text!./css/myStyle.css'

    ],

    function ( $, qlik, test, cssContent ) {

        'use strict';

         ....

         paint: function ( $element, layout ) {

               test.hello();

          }

     });

test.js

     function hello() {

            console.log(' api test: my');

     }

What I get in console is:

TypeError: Cannot read property 'hello' of undefined

My next question is if/when will my external .js file contain some external library (npm install packages), is it enough to just npm install all necessary packages, or do I need to do something else?

1 Solution

Accepted Solutions
erik_wetterberg
Honored Contributor

Re: Qlik Sense Extensions : bring other js files in

Hi,

Your test.js file should define a module that returns an object with a hello method. The define .... return { } is necessary.

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
5 Replies
erik_wetterberg
Honored Contributor

Re: Qlik Sense Extensions : bring other js files in

Hi,

Your test.js file should define a module that returns an object with a hello method. The define .... return { } is necessary.

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
zadravecm
New Contributor II

Re: Qlik Sense Extensions : bring other js files in

Yes this do the trick.

I then found this link that could help others who stumbleupon same problem.

What about my second question? Do you know about npm modules?

zadravecm
New Contributor II

Re: Qlik Sense Extensions : bring other js files in

Also, if I add another method, the error come back. Should be there only one function? This seems like bad design.

How do I make more than one method inside?

define([

               "jquery"

          ],

          function (jq)

{

     return {

          log: function (error, response, body) {

               console.log('test1');

          }

          hello: function () {

               console.log('test2');

          }

     }

});

erik_wetterberg
Honored Contributor

Re: Qlik Sense Extensions : bring other js files in

Hi,

You need to separate the functions with comma:

},

hello: function(){

What you return is just a javascript object, so you need to follow javascript object syntax. Alternatively you could do like this:

var module = {};

module.log = function() {...};

module.hello = function(){...};

return module;

Erik Wetterberg

Please mark as helpful if you find this useful.

Erik Wetterberg
https://extendingqlik.upper88.com/
zadravecm
New Contributor II

Re: Qlik Sense Extensions : bring other js files in

Thank you for that, I miss this

But I still have second problem.

If I do:

     const request = require('request');

I get error....

Do you know how to bring modul to this (separate, with only functions) js file?

Marko

Community Browser