1. Macro’sare bad!
Why you should never use macro’s
Qlik Dev Group NL – October 29th 2015
Not sure if …
2. Qlik Dev Group NL – October 29th 2015
AGENDA
1
2
4
3
Introduction
Developing macro’s
What reference materials are there?
How can you debug macro’s?
What are macro’s?
Where can you find them?
What are the language options?
What use cases are there?
5Some cool and/or useful macro’s
How are we and others using macro’s?
Macro’s myths
Is it true what they say?
2
3. ABOUTBARRYHARMSEN
1 BI Consultant
Working at Bitmetric. Started 15 years ago
in ‘traditional’ Data Warehousing and
Business Intelligence. Switched to Qlik in
2008 and still enjoying it very much.
2 Blogger
Regular blogger at www.qlikfix.com,
together with my colleagues. Focused on
Qlik, with topics ranging from common
challenges to the extremely obscure (some
would say pointless).
3 Author
Authored the book QlikView 11 for Developers
together with Miguel García.
4 Organizer of Qlik Dev Group NL
Started organizing meetup for Qlik
professionals in March 2015. Hobby/fun
project. Help, speakers and sponsors welcome!
3
Qlik Dev Group NL – October 29th 2015
4. WHATIS A MACRO?
“Asingle instruction that expands automatically into a set of instructions to perform a particular task. ”
Scriptto automate a series of steps in QlikView
Found under Tools | Edit Module (Ctrl + M)
VBScript JScript
4
Qlik Dev Group NL – October 29th 2015
6. MACROUSE CASES (1/2)
Custom scriptfunctions Custom chartfunctions Reportgeneration Front-endinteractivity
Create additional
functions that can be
used in the QlikView
script.
Create additional
functions that can be
used in front-end charts.
Generate reports by
making selections and
exporting data and/or
images to Excel,
PowerPoint, Word,
HTML, etc.
Provide additional front-
end interactivity, for
example dynamically
modifying charts or
selections, calling a web
service etc.
6
Qlik Dev Group NL – October 29th 2015
7. MACROUSE CASES (2/2)
Cache warming Mass updates Dynamicupdate Developmentautomation
Timed script that
automatically makes
selections on big server
documents. Ensures that
the results are already
cached for the users.
Perform an ad-hoc mass
update of document,
sheet or object
properties across an
application.
Dynamically insert or
update values into the
QlikView data model.
Automate common
developer tasks, for
example generation of
ad-hoc report objects, or
document layout and
navigation.
7
Qlik Dev Group NL – October 29th 2015
8. MACROUSE CASE CUSTOMSCRIPTFUNCTIONS
Create additional functions that can be used in the QlikView script.
Examples
Regular Expressions*, Levenshtein Distance, SHA-1 hashing*
Alternative: dump table to CSV during reload and process
externally (R, Python, Perl)
8
Qlik Dev Group NL – October 29th 2015
* See: http://www.qlikfix.com/2010/10/18/regular-expressions-in-the-load-script/ for example
** See: http://www.qlikfix.com/2012/06/06/check-if-your-linkedin-password-was-leaked/ for example
Good idea? Depends
9. Requires some additional tweaking touse
Set AllowMacroFunctionsInExpressions to 1
Found in Easter Egg menu: Help | About QlikView | Right-click Q
MACROUSE CASE CUSTOMCHARTFUNCTIONS
Use additional macro functions within expressions in the front-end.
9
Qlik Dev Group NL – October 29th 2015
Good idea? No, unless…
10. MACROUSE CASE REPORTGENERATION
Export QlikView data and objects into external reports, for example in PDF, PowerPoint,
Excel, Word or HTML.
Can be done from within the application, butalso externally
Qlik Dev Group NL – October 29th 2015
Good idea? Depends
Example included in presentation files
10
11. Macro’s are run bythe user using button/text object, or by using
triggers.
Many macro’s do not work in AJAX client, OnPostReload trigger doesn’t
work on server. Can have stability issues or just plain confuse the user.
MACROUSE CASE FRONT-ENDINTERACTIVITY
Add additional ‘pyrotechnics’ to the QlikView front-end, for example changing chart
properties at run time, adding/modifying expressions, etc.
11
Qlik Dev Group NL – October 29th 2015
Good idea? No!
Example included in presentation files
12. MACROUSE CASE CACHE WARMING
Open a (large) document on the QlikView Server and ensure that common user
selections have been made (and cached), before the ‘real’ users log in.
Cache warming improves ‘perceived’ performance
It’s a good idea to first try to improve the actual
performance of an app before using cache warming.
Alternatives: QV Scalability Tools* or Selenium
Qlik Dev Group NL – October 29th 2015
Good idea? Sort of, better alternatives out there
*QV Scalability Tools can be downloaded here: https://community.qlik.com/docs/DOC-6658
12
13. When other solutions do not work, macro’s can be useful todomass
updates
Alternatives: Search & Replace expressions, Search & Replace across Prj-
files, Format Painter, applying themes, etc.
MACROUSE CASE MASS UPDATES
Perform an ad-hoc mass update of documents, sheets or objects. Across an application,
or across multiple applications.
13
Qlik Dev Group NL – October 29th 2015
Good idea? Yes, but be careful, better safe than sorry
Example included in presentation files
14. MACROUSE CASE DYNAMICUPDATES
Dynamically insert or update rows in the QlikView data model.
Trickle load datainto the data model
Partial alternative: Partial Reload
Qlik Dev Group NL – October 29th 2015
Good idea? No, just don’t use Dynamic Updates
Example included in presentation files
14
15. A lazy efficient developer is a good developer!
Minimize time on non-value added activities, so you can spend more
time on the things that really matter.
MACROUSE CASE DEVELOPMENTAUTOMATION
Automate common developer/designer tasks. For example exporting and importing
variables, creating ad-hoc analysis objects, creating navigation and layout object.
15
Qlik Dev Group NL – October 29th 2015
Good idea? Yes, a very good idea!
See http://www.qlikfix.com/2013/09/06/importing-and-exporting-variables/ for an example
17. Qlik Dev Group NL – October 29th 2015
17
DEFAULT DEVELOPMENT ENVIRONMENT
Built-in Module Editor
• Found under Tools | Edit Module
• No-frills
• Kind of a pain to work with
Debugging?
Virtually non-existent, besides
writing values to a message box.
18. Qlik Dev Group NL – October 29th 2015
18
ALTERNATIVEDEVELOPMENT ENVIRONMENT
VbsEdit
• Stand-alone VBScript IDE
• IntelliSense
• Object Browser
• Compile to EXE
Debugging?
Plenty! Add breakpoints, inspect
values and objects at runtime, etc.
What’s the catch?
Not free, costs 49 Euro. Download from http://www.vbsedit.com/
19. Qlik Dev Group NL – October 29th 2015
19
REFERENCEMATERIALS
API Guide
• Provided by Qlik
• Lists simplified object model
• Describes methods and
properties
• Nice collection of sample
macro’s
Check out other people’s stuff
• QlikCommunity
• Blogs Download from https://community.qlik.com/docs/DOC-2640
20. Qlik Dev Group NL – October 29th 2015
20
DEVELOPMENT TIPS
Use Option Explicit
Forces the explicit declaration of all variables.
Use descriptive variable names
So not xyz but wbExport or chProps.
Comment your code
Needs no further explanation, just do it already.
Don’t misuse On Error Resume Next
Only use for error handling, not to mask crappy code
Write reusable subroutines
Compartmentalize functionality so that you can reuse it
across applications, i.e. not “one big subroutine”.
21. Qlik Dev Group NL – October 29th 2015
21
SYSTEMACCESS
When dealing with macro’s that access the system (i.e. stuff outside of QlikView),
don’t forget to enable System Access in the Module Editor.
Requested Module Security shows access level requested by the developer.
Current Local Security shows the access level granted by the user.
22. Qlik Dev Group NL – October 29th 2015
22
INCLUDING MACRO’S
The macro editor doesn’t have the $(include) option that we can use in regular
QlikView script, but we can simulate it, with a macro.
Uses the ExecuteGlobal command.
Allows you to store your macro’s in
external VBS files and include them into
your applications. Useful for version
control.
Read more at http://www.qlikblog.at/509/simulating-include-command-qlikview-macros/
24. Qlik Dev Group NL – October 29th 2015
24
MACROMYTHS
Macro’s are single-threaded
SOMEWHAT
Macro code is executed sequentially (i.e. “single-threaded”) but
each statement can be multi-threaded.
25. Qlik Dev Group NL – October 29th 2015
25
MACROMYTHS
Macro’s clear the cache
FALSE
Any selection that is made by a macro is cached in the same way
as a regular selection made in the UI.
26. Qlik Dev Group NL – October 29th 2015
26
MACROMYTHS
Macro’s clear the undo/redo stack
TRUE
Changing document, sheet or object properties in a
macro will clear the undo/redo stack.
28. Qlik Dev Group NL – October 29th 2015
28
DOCUMENTANALYZER
• Analyzes the structure of a QVW
• Focuses on which fields are used
and where
• Can be used to tune
performance of QlikView
applications or investigate
impact of data changes
• Made by Rob Wunderlich
Download from http://qlikviewcookbook.com/tools/
29. Qlik Dev Group NL – October 29th 2015
29
COPYGROUPS UTILITY
• Copy cyclic and drill-down
groups from one QlikView
application to another.
• Yes, it’s Rob again
Download from http://qlikviewcookbook.com/tools/
30. Qlik Dev Group NL – October 29th 2015
30
QLIKVIEW MACROCOLLECTION
Collection of macro’s by Lucian Cotea
Examples for:
• Exporting JPEG’s
• Exporting to Excel
• Sending emails
• Setting Autozoom
• Creating variables
• and lots of other stuff
https://luciancotea.wordpress.com/2013/07/18/qlikview-macros-useful-collection/
31. Qlik Dev Group NL – October 29th 2015
31
TURBOQLIK
Internal Bitmetric tool, used for:
• Template / layout generation
• Color management
• Variable management
• Ad-hoc report object generation
• Object library
• And whatever makes our life easier
34. SOCIAL MEDIA
Twitter Google+ LinkedIn
https://twitter.com/meneerharmsen https://plus.google.com/+BarryHarmsen http://www.linkedin.com/in/barryharmsen
Qlik Dev Group NL – October 29th 2015
34
35. CONTACT INFO
Bitmetric B.V.
Planetenweg 5
2132 HN, Hoofddorp
TheNetherlands
barry@bitmetric.nl
+31 (0)23 2302 062
+31 (0)62 4581 706
35
Qlik Dev Group NL – October 29th 2015