Script Editor Features and Commands in QlikView

The QlikView Script Editor is the main workplace for developing the scripting elements of QlikView application. Some useful features in the Script Editor include certain menus. The menus described in this chapter are found in the menu bar at the top of the screen. Most commands can also be configured as buttons in the toolbars. The following post gives you an overview on the various menus:

Learn how to use QlikView, from beginner basics to advanced techniques, with online video tutorials taught by industry experts. Enroll for Free QlikView Training Demo!

The File menu

The File menu is a drop-down menu at the top of the screen, and contains the following commands. It contains commands regarding saving the script and document, reloading, importing scripts, hidden scripts, and access to the Table Viewer.

Related Article: Snowflake and Star Schema in Qlikview

The Edit menu

The Edit menu contains basic script editing and tidying commands that make the script easier to read, or disable (via commenting) blocks of script code. Let’s have a look at the commands:

MindMajix YouTube Channel

The Insert menu

The Insert menu contains powerful commands to insert many types of script elements into the script code, from variables to including files and connecting statements. Let’s have a look at the commands:

The Tab menu

As QlikView applications grow, the number of tabs that information is spread across can grow rapidly as well. The Tab menu is helpful in creating script tabs, moving the tabs to the left and right (promoting and demoting tabs) as well as renaming, merging, and removing tabs. Remember that tabs are a way of organizing and ordering script execution, and the script execution runs from the top of the leftmost tab to the bottom of the rightmost tab. Let’s have a look at the commands:

Related Article: QlikView IntervalMatch Function

The Tools menu

The Tools menu assists with setting up the correct ODBC connection, setting the Script Editor preferences, and providing a quick syntax check feature. Let’s have a look at the commands:

The Help menu

The Help menu displays help information for the specific section of QlikView which is active.

The Tools pane

The lower section of the Script Editor window is referred to as the Tools pane. This section has four tabs: Data, Functions, Variables, and Settings. The Tools pane of the Script Editor is where data sources are defined and connection strings are created, functions and values are created and edited, and other system settings are made.

Script commenting

Script commenting is a powerful way to organize, describe, and disable/enable lines or an entire section of your QlikView script. You can insert comments and remarks in the script code, or deactivate parts of the script code by using comment marks. For instance, it is QlikView’s best practice to include an explanatory comment before each Load script for a table. Adding comments to code is also necessary for later code review and editing by other QlikView developers. Often, code created one month ago will be difficult to understand during later months when being reviewed (even by the same developer!). Commented code will be marked by QlikView as green text. Following are some of the methods of script commenting available to you:

Related Article: QlikView Interview Questions

Do the following:

1. Select one or more lines of code that are not commented out, or place the cursor at the beginning of a line.
2. Click …, or press Ctrl+K.
The selected code is now commented out.

Uncommenting

Do the following:

1. Select one or more lines of code that are commented out, or place the cursor at the beginning of a commented line.
2. Click …, or press Ctrl+K.
The selected code is now not commented out.

Creating the Select statement

Assume that you have any database on your computer or server (Access, MySQL, Oracle, or otherwise— these illustrations use the free Microsoft Access 2010 database, Northwind1, on a system running the 32-bit Office 2010), assure that you have the correct driver on your machine; if you are running the 32 bit Microsoft Office 2010 and accessing the newer format of the Access .accdb file. You will need to download and install the 32-bit Microsoft Access Database Engine 2010 Redistributable driver. Let’s walk through creating a brief script in QlikView’s Script Editor window.

To get to the Select Statement dialog, you have to first connect to a database. The following example illustrates a connection to a Microsoft Access 2010 .accdb database file. Modify it as you need for your database or data source type.

1. Start by opening a new QlikView document (click on Cancel when the Select Data Source wizard appears). Go to the Script Editor (navigating to File | Edit Script from the main QlikView toolbar).
2. In the Data tab in the Tools pane of Script Editor, select OLE DB and check the Force 32 bit DB checkbox (we want QlikView to look for installed 32-bit connections).
3. Establish the connection to the database and insert the connect statement in the script by clicking on the Connect button on the Data tab in the Tools pane, and proceeding through the Data Link dialog.
4. Select Microsoft Office 12.0 Access Database Engine. On older systems or to access older Access .mdb databases, select the Microsoft Jet 4.0 OLE DB driver.
5. Click on the Connection tab and enter the full pathname and filename of the .accdb database. Also, enter any connection login credentials if required.
6. Test the data connection. If successful, click on OK, and then connect statements will be displayed in the script window.
7. Click the Select button in the Tools pane to proceed to the Create Select Statement dialog. The Create Select Statement dialog will be populated with the database tables and fields for your selection. If the connection was not successful, troubleshoot the connection credentials and path/ filename.

Building the Select statement

Once we’ve connected to the database, the Create Select Statement dialog appears and allows you to customize and narrow your selected statement by selecting various tables and files.

By default, the first table in the list is selected and all columns (select all or select star with an asterisk) are selected. Each Select statement can load information from one table and multiple columns (database fields).

In this example, we will select (Ctrl + click) from the Customers table using the following columns: Address, City, Company, Country/Region, E-mail address, First Name, Last Name, Mobile Phone, State/Province, and ZIP/ Postal Code. Leave checked the Preceding Load checkbox and click on OK.

The load /select statement is displayed in the script area in the script editor dialog. Note that QlikView syntax load statement appears above the SQL select statement, as shown in the following screenshot:

Running your script and viewing results

Click on Save and then on the Reload button. The Script Execution Progress dialog appears briefly and the Script Editor closes, with the main QlikView screen (sheet) open to the Sheet Properties dialog. This is the sequence you will see each time after reloading a script. It is fine to click on Cancel in the Sheet Properties dialog, unless you would like to add one or more fields to the existing sheet.

Click on Add All and then on OK to display all the available fields on the sheet. All fields are displayed as listboxes on the main QlikView sheet. Select the Layout | Rearrange Sheet Objects menu command to organize the list boxes. Make some selections and see how the data changes based on these selections. Click on the Clear button to reset the selections.

Organizing tabs in scripts

There are many preferences when choosing the script architecture, but the one most accepted, in the QlikView community, is dividing script tabs by data source and also creating additional tabs for the master calendar, variables, mapping tables, and also cleanup procedures. Remember that the scripts are executed from top to bottom and from left to right, so the tab scripts must be executed in the correct order.

Now that you’ve seen how to connect to a data source and load fields from database tables, you may be wondering about how to organize the tabs in the QlikView Script Editor window. It will help to put some thought into the script architecture up front: how will the tabs be organized— by function or by the application tab? How about by data source? How will you handle variables? Mapping tables?

It’s up to you, and it will probably be a hybrid approach. There are two main schools of thought in the QlikView community about tab organization: some say to organize them by data source and some say to organize them by QlikView application’s (QVW) user interface sheet tabs (for instance, each sheet tab will have a corresponding script tab).

The best way to organize and add tabs is likely the division along data source lines, with no consideration of the final user interface, QVW. Remember that the tab order is important and connections and selections must flow in a logical order (promote or demote tabs as needed and add new tabs using the Tab menu). You may want to add other tabs as well, such as mapping tables, variables, cleanup procedures, and exit script.

Whatever you do, make your tab names and tab order very descriptive and logical, and add plentiful comments to describe various parts of the script for easier maintenance later on.