QlikTip #21: Running QlikView 8.5 and QlikView 9 side by side

Just a very short (very, very short) tip today.

I was asked how one could run QlikView 8.5 and QlikView 9 one one system …

That’s absolutely no problem.

During the installation of QlikView 9 Desktop (when having QlikView 8.5 already installed) just choose another installation path as suggested (e.g. C:\Program Files\QlikView_9 instead of C:\Program Files\QlikView) and these two versions will run on one system without conflicting each other.

That’s all … :)

Note: This works for me on Windows 20003 Server, Windows XP, Vista and Windows 7

Bookmark and Share

Tags: , ,

QlikTip #20: Why we do not need a SELECT-CASE/Switch-Case in QlikView load-statements …

I have recently received the question why there is no SELECT-CASE or SWITCH statement available in QlikView within load-statements.

Sure, if you are looking into the reference-manual or into the help file, you’ll find the SWITCH-CASE-statement, but this is a control statement so it cannot be used within a load-statement, e.g. this is possible

switch I
    case 1
        load '$(I): CASE 1' as case autogenerate 1;
    case 2
        load '$(I): CASE 2' as case autogenerate 1;
    default
        load '$(I): DEFAULT' as case autogenerate 1;
end switch

But this not:

// Note: this pseudo-code will not work!!!
LOAD
     Profession,
          (SELECT CASE Profession
               CASE 'Profession A': 100
               CASE 'Profession B': 200
               CASE 'Profession C': 300
               CASE 'Profession D': 400
               DEFAULT: 1000
          END SELECT) as RISK_CLASSIFICATION
RESIDENT FirstTable;

Even if I do not really know why QlikTech has not implemented this, we do not really need it.

Instead of using a SELECT-CASE (SWITCH-CASE) functionality in load-scripts we can easily use ApplyMap method:

Let’s think about the following scenario:

  • We have a field called “PROFESSION”
  • Depending on the values in this field we want to create a field “RISK_CLASSIFICATION”

Let’s create a sample for loading the field “PROFESSION”, would normally be loaded from your database or other data-sources:

FirstTable:
LOAD * INLINE [
    Profession
    Profession A
    Profession B
    Profession C
    Profession D
];

In the next step we create a mapping-table and use the applymap:

Map_Classification:
MAPPING
LOAD * INLINE [
    Profession, Classification
    Profession A, 100
    Profession B, 200
    Profession C, 300
    Profession D, 400
];

Qualify *;
SecondTable:
Load
	Profession,
	// Use the applymap to classify the profession, 1000 is the default-value
	// if the applymap does not find a match
	applymap('Map_Classification',Profession,1000) as RISK_CLASSIFICATION
RESIDENT FirstTable;

This will result into:
Result of the tables in QlikView after using the applymap





Bookmark and Share

Tags: , , , , , ,

QlikTip #19: Suppressing Macro-Security (Module Security) Dialog on QlikView-Server/QlikView-Documents

When opening documents with macros the end-user will be shown a dialog to define the desired macro-security/module security (in the QlikView Windows Client or the QlikView IE Plugin):

The module script in this document contains code that accesses the system or applications outside QlikView. What security level do you want to give the macro module of this document.

But what, If you do not want that the end-user has to option to select the desired macro security/module security?
You can (e.g. as a system-administrator) globally enable the module-security at the highest level (“Allow any Macro (only for trusted documents)”) for every QlikView-Server you have by running the following script.
This script adds a registry entry to HKCU\Software\QlikTech\QlikOcx\Settings for Qlikview Servers\:

'// **************************************************
'// Script for adding some registry keys to the current user profile/registry settings
'// for enabling the macro security/module security for the SERVER defined below
'// ~
'// CONFIGURATION
'// Just configure the script by defining your server below
'// ~
'// The article explaining this script can be found at
'// http://www.qlikblog.at/523/
'// **************************************************
CONST cSERVER_NAME = "YOUR_SERVER_NAME"
Dim WshShell 'as Object

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\QlikTech\QlikOcx\Settings for Qlikview Servers\", 1, "REG_SZ"
WshShell.RegWrite "HKCU\Software\QlikTech\QlikOcx\Settings for Qlikview Servers\Module Script System\", 1, "REG_SZ"
WshShell.RegWrite "HKCU\Software\QlikTech\QlikOcx\Settings for Qlikview Servers\Module Script System\ " & cSERVER_NAME, "", "REG_SZ" 

That’s it!
By doing so the end-user will never be asked again to choose the desired macro-security/module security.
You could for example run this script together with other logon scripts, it does not matter if you run this script multiple times!

Bookmark and Share

QlikTip # 18: A workaround for passing parameters to QlikView-macros

When calling macros from the user interface you cannot pass a parameter to the function called in QlikView.

This behavior is quite annoying …!

But the workaround explained here will show you a possibility how you can “simulate” passing parameters to macro-functions:

The idea behind is quite simple. In QlikView 9 we have now actions which can be added for any event (e.g. the OnClick event for buttons). The clue is that we can add multiple actions for every event, so I am doing the following:

OnClick Event for Button “cmdXY”:

  • Changing the value of a variable (e.g. vValueToDisplay)
  • Calling a function/sub in your macro (e.g. cmdXY_OnClick)
  • Within the macro and the function cmdXY_OnClick I am first retrieving the value for the variable vValueToDisplay, then I am executing the “normal” macro-code using the value read from the variable

Step by step with some screenshots:

First let’s create the variable vValueToDisplay:

Create the variable vValueToDisplay

Then let’s create some buttons:

Now we have to assign the actions for “Button 1″:

Adding the action of Action-Type "External" and "Set Variable" to Button 1

Explanation:

  • Go to the properties of the button
  • Change to the Tab Actions
  • Then select Action-Type External and Set Variable

Then we set the desired parameters:

Then we have to trigger the macro:

  • Add a second action of Action-Type External and Run Macro and enter the following values:

So, we have nearly finished, the last step is to create the macro (Go to Tools => Edit Module or use Shortcut Ctrl+M):

'// *************************************************************
'// Displays a simple message-box, showing the value of the
'// variable vValueToDisplay
'// ~~
'// This sub assumes that the variable "vValueToDisplay"
'// has been set before !!!
'// *************************************************************
sub GenericClick

'// First let's retrieve the content of the variable "vValueToDisplay"
Dim strValueToDisplay 'as String
strValueToDisplay = ActiveDocument.Variables("vValueToDisplay").GetContent().String

'// Create an alert
msgbox("The value of ""vValueToDisplay"" is: " & strValueToDisplay)

end sub

Clicking on the button will now show the content of the variable:

Further examples:

Please find some further usage-examples in the following QlikView-example-application:

How I am using this:

The example above is quite simple. In reality I am using for more complex situations, e.g. for creating Excel-sheets and so on. Therefore I am setting some variables before and then I am calling the desired function which requires the above variables to be set before …

Note at the end:

In my example you’ll find a sheet “Testing Real Parameters” where I have tested passing “real” parameters to macro-functions, but did not succeed.
Maybe I just did not manage to call a macro with a parameter correctly … If so, please tell me! :)

Bookmark and Share

Tags: , , , , , , , , ,

QlikTip #17: Simulating the $(include) command in QlikView macros

Within load-scripts in QlikView there is the useful “$(include)” command available for including files containing some script to be used within the load-script.

Doing so it is easy to encapsulate and reuse some code used in several QlikView applications.

So organizing your code in load-scripts is easy, you can use several tabs and the $(include) command, whereas QlikView is not offering similar possibilities in the macro-editor. There are no tabs and “officially” there does not exist an corresponding command for including code in macros.

But that’s not the whole story, there is a nice possibility:
QlikTech is using the VBScript engine for interpreting the macro code by default (you could also use the JavaScript engine …). In VBScript there is a not very well known command called “ExecuteGlobal” (Official reference at MSDN, which “executes one or more specified statements in the global namespace of a script.”

So can we use that in QlikView macros?

Yes, we can!

Dim objFSO 'as Object
Dim objFile 'as Object
Dim strScript 'as  String

'// Open the File using File-System-Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("SOME_SCRIPT_TO_ENCLUDE.vbs")

'// Copy the content of the file
strScript = file.ReadAll

'// Just destroy the objects again
Call objFile.Close()

'// Execute the script globally
Call ExecuteGlobal(strScript)

Doing so at the beginning of the script you can now use the content defined in SOME_SCRIPT_TO_ENCLUDE.vbs in the subsequent macro code.

Because I am using this possibility of including existing scripts quite often I have improved the code above a little bit and created a function which I use in every application where I need this stuff:

'// *****************************************************************
'// Function for executing external content in your application.
'// ~
'// Parameters:
'//	p_strFilePath – full absolute path in relation to the QlikView application
'// ~
'// Return Value:
'//	Will return true if succeeded, otherwise false (e.g. if the file
'//	does not exist)
'// Examples:
'//	IncludeAndExecute(“D:\QlikView\Scripts\FileFunctions.vbs”)
'// Further information: http://www.qlikblog.at/509/
'// ******************************************************
Private Function IncludeAndExecute(ByVal p_strFilePath) 'as Boolean

'// Variable declaration
Dim objFSO 'as Object
Dim objFile 'as Object
Dim strScript 'as  String

'// Open the File using File-System-Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")

'// prevent errors ...
On Error Resume Next

	Set objFile = objFSO.OpenTextFile(p_strFilePath)

	'// Copy the content of the file
	strScript = objFile.ReadAll

	'// Just destroy the objects again
	Call objFile.Close()

	'// Execute the script globally
	Call ExecuteGlobal(strScript)

	'// If an error occurred just return false
	If (len(Err.Description) > 0) Then
		IncludeAndExecute = false

		'// Just comment the following line if you want to suppress messages
		'// in case of errors
		msgbox(Err.Description)

		Exit Function
	End If
On Error Goto 0

IncludeAndExecute = true
End Function

And then I am using this code as follows:
Final Result when using the function IncludeAndExecute multiple times

For testing purposes you can download all the scripts and a sample application by clicking on the link below:

Advantages

  • Code reuse and code encapsulation is easier
  • Because you are now only using text-files integration into CVS-systems will be easier!
  • Because of using the File-System-Objects (FSO) you have to enable “System Access” in the macro-security settings!!!

Disadvantages

  • You are creating an unnecessary, artificial dependency between the included scripts and your QlikView-applications! So certainly you have to take care when changing your global scripts …
Bookmark and Share

Tags: , , , , , ,

A little tool for creating nested if-statements

Nested If-statements are sometimes necessary in QlikView- load-scripts, unfortunately.
They are quite difficult to read and very tricky to create and especially to debug.

In the last recent months I had a lot of projects where a tenfold nesting of if-statements was not uncommon.

After struggling with these nested ifs for a while I decided to create a little user-interface which helped me to decrease the time for creating nested if-statements.
Even if this tools is just a little, little helper it may also be helpful for you, so I decided to publish it here:

Try the “Nested If Generator” now

Some screenshots and explanation:

At the beginning you can define the “fieldname” to be generated” and define your first if-statement:
Let’s assume you are checking the two fields “Age” and “Profession”:

Defining the first if-statement

Defining the first if-statement

If you want to add an additional if-clause just click on “Add another IF-block”:

Adding a second if-statement

Adding a second if-statement

As you can see when comparing the two screenshots above the “else-block” of the first statement was removed and replaced by an additional if-clause.

After some further if-blocks the configuration could look like as follows:

After adding several if-statements

After adding several if-statements

Now the last step is easy, change to the “Generated Code” tab and copy your code:

Generated Code to be used in QlikView

Generated Code

The Tool is offering three different “Formatting Styles”:

Single line formatting

Single line formatting

Single line formatting

If-statements formatted like this were the main-reason for creating this tool :)

Indent style with one line per condition

Indent style with one line per condition

Indent style with one line per condition

This is my preferred formatting-style for really large if-statements with complex conditions

Indent style with one line per if-statement

Indent style with one line per if-statement

Indent style with one line per if-statement

This is my preferred formatting-style for if-statements with short conditions like demonstrated in this example …

Have fun :)

Bookmark and Share

Tags: , , ,