Using ChatGPT to create Qlik Sense scripts

Can a language model like ChatGPT be used to create code for Qlik Sense? The answer is yes - and no. It's very impressive indeed but doesn't quite replace us humans yet.

Using ChatGPT to create Qlik Sense scripts
Photo by Andrea De Santis / Unsplash

By now everyone has heard about ChatGPT and the wonders it can do when it comes to understanding and creating text.

The conversational chatting with ChatGPT is  fun and results in texts that are in many cases as good as - or better - than texts I write myself. Pretty mindblowing when thinking about it.

I have however nurtured the idea that if you work in the intersection of several fields and do very specialised work it will be harder for a tool like ChatGPT to create useful things. Or when directing it towards niche fields for which there is (relatively) little material about online - such as Qlik Sense development.

Spoiler alert: I was both right and wrong.

The other day i casually started to ask Qlik Sense related questions to ChatGPT. The results range from plain wrong to pretty amazing. Either way it's food for thought for those of us doing Qlik related work.

Or rather - for now there is certainly work also for us humans. ChatGPT and similar tools have a surprisingly high level of understanding of Qlik related topics, but it really only works on small, isolated problems, pieces of code and similar. The larger context needed to create an analytics solution still needs a human. But as a tool for creating better code, one piece at a time, ChatGPT can certainly be useful, as we will see.

Key takeaways include that it creates surprisingly well written Qlik script, for example using very good variable names. It also understand rather complex concepts like tables, joins and app indexing.

But it is also always equally sure of itself - even when creating things that are simply incorrect.

Bottom line is that the results can be quite useful but you have to view them critically - the results can provide ideas and guidance, but rarely complete solutions.

Follow along and see what can be done today - below are some real sessions I've had with ChatGPT over the last couple of days.

Do you Qlik?

Ok, let's put it to the test..

Load data from QVD file

Very cool. It has marked the suggested script as being VB.Net, which is not  correct. This makes the syntax highlighting to be incorrect, but that's a minor thing.

To me the most interesting thing is that it seems to understand Qlik script, even though Qlik script is (let's be honest now..) a pretty minor language in the wider IT landscape. For example, look at the parenthesis in "(qvd)".

Incremental load from QVD

Here it creates some script labeled "scss", with associated syntax highlighting. Room for improvement there, but again this is a minor thing.

At a first glance the suggested code looks pretty good. But...

  • The FileName function doesn't tell us if a file exists or not, right?
  • Maybe there should have been a "NoConcatenate" statement in the second load, to avoid loading the risk of the second load from file going into the first table?
  • What happens with the Join if that first QVD doesn't exist?

Pretty ok result but not something that would run as-is.

Load multiple QVDs from disk

  • The code is somewhat naive, a looped approach would probably be prefered in many scenarios.
  • The use of lib:// paths is correct.

Control indexing of Sense app using script statements

Now let's give ChatGPT some existing Qlik script to analyse. We will use a set of Subs that let you control indexing of apps during the reload (very useful subs btw!)

Well, that's an excellent explanation of those four subs. Very impressive.

Let's try again, but without the embedded comments in the script we give it. Will it still be able to explain what the code does?

Indeed it does. We can only guess how it achieves this. By scraping the Qlik help pages, by learning from my previous question or something else - who knows?

Impressive nonetheless.

Comment an existing Sense script

Can ChatGPT asssit in adding comments to existing Sense scripts? Let's use the same four subs again.

Yes, here it's doing a pretty good job even though it insists of saying it's VB.Net...

Explain what canonical dates are

HIC's text about canonical dates is a classic. Let's see what ChatGPT can make of the script in that blog post:

It's a correct description and may very well help understanding the concept of canonical dates. Note that I did not mention in the question that this was Qlik script, but as ChatGPT keeps a rather long session context it still (correctly in this case) assumes that it's dealing with something Qlik Sense related.

Use Javascript to call the Qlik Repository Service API

Let's see if it can generate code that calls the Qlik Sense repository API.

I expect the result to be better here as Javascript is a much (!) more widely known language. ChatGPT should have a better understanding of what Javascript code should look like.

Easy enough question, right?

The response is pretty awesome. Not perfect, but a really good start for anyone new to the QRS API.

  • It uses the about endpoint in the QRS api. This endpoint exists, indicating that ChatGPT know about the ins and outs of the QRS API. That's... insane.
  • It knows about the need for using a "X-Qlik-Xrfkey" header, but it doesn't add the associated "xrfkey" URL parameter. Good, but not perfect.
  • It uses bearer authentication, which is not commonly used with Sense. But if you have an JWT enabled virtul proxy it will certainly work. And of course, the easiest way to create JWTs for Qlik Sense is the open source qs-jwt tool 😉.

Use Javascript to get all custom properties and their values from QRS API

Similar to the previous question, does ChatGPT understand the intricacies of the QRS API? Can it retrieve a list of all custom properties including their values from the API - and limit itself to only custom properties that are defined for reload tasks?

Comments:

  • It uses an endpoint "/api/v1/reloadtasks/customproperties/full", which does not exist according to the API docs. Looks like it just made up a path that sounds good... Creative but not very useful.

Running a very similar query gives a rather different result, which is interesting:

Comments:

  • It uses the correct /custompropertydefinition/full endpoint.
  • It does not use the correct port for the QRS API. Should be 4242. It seems a bit ambivalent here, in some queries it will include that port in the suggested Javascript code, other times not.
  • It incorrectly uses a property "entityType" to determine whether a custom property is available for reload tasks. That property does not exist in the reply from the QRS API.

Create a QVF file that can be imported into Qlik Sense

Finally, let's see if ChatGPT can create a complete Sense app for us.

Nope, no QVF generation available. But a nice little demo script to get started with.