Tutorial Tuesday: Implementing version control for Qlik Sense with Git, GitHub and Visual Studio Code

By Vincent Hayward

Welcome to my second Blog post, which will be a basic tutorial of how to setup a lightweight version control for Qlik Sense script. This approach is straight forward to implement in various occasions. My aim is not to over complicate version control by offering this as a nice beginners guide on version control and workflow.

This tutorial will be part of a series of Tutorial Tuesdays that will lead to a lightweight, straight forward and easy to implement framework within Qlik Sense. In the series of tutorials hereafter will we cover topics as version control with script changes, different localization settings, loading centralized variables, creating master items on variables and eventually getting a simple dashboard up and running based on all tutorials altogether.

This tutorial is divided into 4 parts, in part 1 we will set up a remote environment for Git repositories at GitHub, in part 2 we will install local software, in part 3 we will building your project and part 4 is committing changes and synchronizing with the remote repository at Visual Studio Code.

Why use version control?

With version control you keep track of any changes to the code. If an error is made, you can roll back to a previous version of the code and you can compare previous versions of the code to correct the error and minimize disruption for other developers. Version control protects source code from catastrophes, human errors and / or unintended consequences of changes.

Before we start we need to download a bit of software, like Git and Visual Studio Code, the installation of which will be covered in part 2. As well as creating an account at GitHub, the configuration of which will be covered in part 1.

Part 1 – Setting up a remote environment for Git repositories at GitHub

Login at Github

First we are going to set up the GitHub by creating an account and then sign in. After you have signed in; you can create a new repository by clicking on the “New” button on the left part of the screen.

Create a new repository at Github

At the new page with the title “Create a new repository” you can fill in the details, as repository name, description and set the repository on public / private and then click Create repository.

Filling in the repository details

After creating the repository successfully you will end up at the repository page of the created repository bitmetric_random_sales_model, where we can copy the HTTPS link for further use.

Repository tab code

Now the remote repository has been set up at GitHub, we can continue with the installation of Git.

Part 2 – Installation of local software

If you haven’t downloaded Git yet, you can download it at
Git. The installation of Git is pretty straight forward, which means pretty much clicking the [Next] button up to the moment Git has been successfully installed. So keep all the settings as default selected during the installation process.

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency and Git is by far the most widely used modern version control system in the world today.

After you successfully installed Git as the SCM, it’s time to install the code editor Visual Studio Code. The installation of Visual Studio Code is pretty straight forward as well. After you successfully installed Visual Studio Code, you may open the application.

Welcome screen of Visual Studio Code

The first screen you see when opening Visual Studio Code is the Welcome screen, which can be closed. At this point we haven’t connected Visual Studio Code with a source control provider yet. So the next step is installing the extension Git History. Click Shift + Ctrl + X to go the Extension Marketplace and search for the extension Git History and install it.

Install extension Git History

So now we have installed everything we need in order to set up a workspace folder by cloning the online repository at GitHub, we have setup at Part 1. Open the Command Palette (Ctrl + Shift + P) and type in Git, as you can see different commands started with Git appear. Choose Git: Clone.

Clone GIT repository

After you started the command Git: Clone you need to enter the repository url from Part 1 at GitHub and in my example that would the URL https://github.com/vmfhayward/bitmetric_random_sales_model.git

After you entered the repository URL, you will need to select the workspace folder. In this case we are going to E:\Qlik Sense Repositories and press the button [Select Repository Location]. Now the repository at GitHub has been connected to E:\Qlik Sense Repositories\bitmetric_random_sales_model

Select the target folder for the GIT Repository to clone to

Now when successfully followed the steps above we get a message at the bottom right of the screen “Would you like to open the cloned repository?”. Now click on Open Repository and you will automatically return to the Explorer menu, where the folder bitmetric_random_sales_model has been added. But is yet empty!

So let’s create our very first file at the workspace folder. To do so click on the new file icon next to bitmetric_random_sales_model and name the file
named Bitmetric Random Sales Model.qvs

(Animated GIF) Creating a new file Bitmetric Random Sales Model.qvs

Now that you have created an empty file Bitmetric Random Sales Model.qvs, we can go to Qlik Sense and create an application.

Part 3 – Building your project

The next thing we can do is creating an Qlik Sense application and move the localization settings that is generated automatically from the Qlik Sense application to the script we created in part 3. In our example we created an application in Qlik Sense Desktop called Bitmetric Random Sales Model.

Open the Qlik Sense application and select and cut the script and then paste this script in the Bitmetric Random Sales Model.qvs at Visual Code Studio. Now switch back to the Qlik Sense application and add the following line:

$(MUST_INCLUDE=[lib://Bitmetric Random Sales Model/
Bitmetric Random Sales Model.qvs ]);

(Animated GIF) Get script from Qlik Sense application and replace it with an include to the script file
(Animated GIF)Adding script tot the script file Bitmetric Random Sales Model.qvs

Now we are almost done!

So at this point we have created a script file with lines of Qlik code, both localization settings as well as a data model script by remote include and we have added the script file Bitmetric Random Sales Model.qvs to our Qlik Sense application with an include line.

Script file Bitmetric Random Sales Model.qvs
Include of Bitmetric Random Sales Model.qvs in Qlik Sense application

At this point we can of course load the application successfully and get some data to work with. But we still need to push the local script file Bitmetric Random Sales Model.qvs to our remote repository at GitHub.

Part 4 – Commit changes and synchronize with the remote repository at Visual Studio Code

So first we need to commit the changes of the file at Visual Studio Code with Source Control (Ctrl + Shift + G), then at Changes you see the file Bitmetric Random Sales Model.qvs. Click on the + icon to stage the changes of this file. Add some text i.e. description what you have changed or a ticket / request number, where you see “Message (Press Ctrl+Enter to commit)” and then commit the changes by clicking the V-icon.

(Animated GIF)Commit changes of the script file Bitmetric Random Sales Model.qvs

After you have committed the changes, you can synchronize it with the remote repository at GitHub by clicking synchronization-icon (circle with the 2 arrows) bottom left of Visual Studio Code. After you have synchronized is successfully you can check the results at your GitHub account.

(Animated GIF) Synchronize your workspace folder with your GitHub repository

If everything went well you will end up with the script file in your remote repository at GitHub. Every time you do changes in your script, just commit them within Visual Studio Code and synchronize them to GitHub. This way you can access your script whenever and wherever.

The GitHub Repository is synchronized succesfully

Now you are all set!

Bonus

With Visual Studio Code the following extensions could become very handy to add to your developer toolkit: Excel Viewer, Qlik and vscode-icons. But remember to reload Visual Studio Code after installing extensions to activate them properly.

A good video about changing script and committing changes can be found at https://scotch.io/tutorials/git-integration-in-visual-studio-code