Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Lee_Matthews
Former Employee
Former Employee

How to access system objects inside extension object script?

I am creating an extension object to display some text in a scrollable box in QlikView - just like an HTML textarea element. The text in the box will be populated from an external source, and the user will be able to edit the text and click a button to save it back to the source. To start with I am trying to get the text from (and store it) in an xml document or even just a text file. But I am finding that when I try to instantiate a filesystem object or xmldom object in the script it does not work. I assume a DB connection object would be the same.

Should the extension object javascript be able to reference system objects such as ActiveX, ADO and FileSystem?

I have set the module security to allow System Access, but does that also relate to extension objects or is there some other configuration I have missed?

Message was edited by: Lee Matthews

13 Replies
Alexander_Thor
Employee
Employee

In general no. JavaScript running in a browser are in a sandbox mode are not able to reference local system resources. The module security settings do not affect extenstion objects since it only relates to macro.

However, with the html5 spec things changed (No I know the File API is a stand alone spec). You can now work with local file storage on the client to avoid to old cookie hacks you had to do to preserve state for example.

Read: http://www.html5rocks.com/en/tutorials/file/dndfiles/

But do you really need to store the text in a file? Can't you just insert the text as a textnode in the DOM of your object? Make sure you don't repaint for every update and it should persist until the user switches sheets or the application times out.

If you want to take the File route here is a very good demo to do something similar: http://html5demos.com/contenteditable


You would have to send the data out to a server based resource to update your source system.

or instance a ADO object through the ActiveX object but that is really really ugly...

Lee_Matthews
Former Employee
Former Employee
Author

Thanks Alexander. I will take a look at the links, but if it only gives access to the user's PC I dont think that will work. Once the user enters text into the text box I need to store it somewhere on the server and associate the text with a key value (eg. postcode), so I can retreieve it when the user selects that key value again. If I cant define a connection to a database or file on the server in the javascript, then perhaps I will have to reference the extension object text from a macro. Do you have any idea how to do that? As it is an extension object I expect all of the standard methods available in the API for interacting with objects do not apply.

Alexander_Thor
Employee
Employee

Well, it can't be done by only javascript running in a browser.

Your client side code, the extension object, would have to talk with a server component.

This could be asp, php, javascript, ruby, python etc etc that resides server side and can handle your request.

Reading a file can easily be done with a ajax call in javascript and then having a php-script to handle write back.

I think you posted an example of a soap webservice call in macro form quite recently, port that over to javascript and you have your solution

Well we do provide a couple of different APIs. The automation API is the one you usually work with over COM to write macros for the desktop and IE-plugin client.

For the AJAX-client, extensions and web deployments we have the JavaScript API and you do have similar functionality even if the automation api is a bit more advanced.

Here is a good write up on what Javascript CAN'T do (even if the local file sitution is solved with html5) http://javascript.about.com/od/reference/a/cannot.htm

Alexander_Thor
Employee
Employee

We put out a Google BigQuery integration app called American Birth Statistics this morning.

http://eu.demo.qlik.com/QvAJAXZfc/opendoc.htm?document=qvdocs/American%20Birth%20Statistics.qvw

It has a good example in it on doing both ajax calls and xhr requests.

Check the myfunctions.js, from line 260-350 it showcases how to get data.

Lee_Matthews
Former Employee
Former Employee
Author

Thanks very much Alexander.

I should have realised that the javascript environment was limited to client side. But I have seen some examples of customisations where things seemed to be operating on the server side as well. (The R integration Elif did for example has an extension object embedded but it also calls a COM object that is sitting on the server in macro code). I am still working out how these various components interact together, and taking some time to pull apart working examples is a big help. I will have a look at how the BigQuery example works as well. Thanks very much for the feedback.

Not applicable

Alexander

How do we see the myfunctions.js. I see no option allowing download anywhere.

Not applicable

If you dig around the source you can find myfunctions.js

http://eu.demo.qlik.com//QvAjaxZfc/QvsViewClient.aspx?public=only&name=Extensions/GoogleBigQuery/MyF...

Don't ask me how it works though! 

Not applicable

That link does not work...  Can you post the entire extension in a zip file?

The link give the following error

The XML page cannot be displayed 

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later. 


Invalid at the top level of the document. Error processing resource

Not applicable

Just right mouse click on the link, select "Save as...", save it to your PC, and open the file with WordPad or some other text reader.  If you simply click on the link your browser will try to interpret the Javascript and give you an error.