Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
hic
Former Employee
Former Employee

There are several good reasons not to use macros in QlikView.

 

First of all, macros are run using Microsoft COM Automation. They will run client-side and work fine if you use the Desktop or the IE PlugIn, which both are Windows executables. But if you use the Ajax client, there are severe limitations since the macros now need to run on the server instead of on the client. For a server, there are both technical limitations and security implications that have forced us to restrict the capabilities of macros.

 

So, if you want to use the Ajax client, you should avoid macros.

 

Trigger.png

 

Secondly, a common beginner’s mistake is to use macros to build logic into QlikView; logic that almost always works better if QlikView’s own out-of-the-box functionality is used.  An example is assigning a value to a variable every time a selection is made: In other tools you would use a trigger and a macro, but in QlikView this is not needed: You should instead define your variable using an equals sign and the appropriate expression.

 

Further, many problems can be solved by using a smart data model instead of macros.

 

Macros often confuse the user. A user wants a predictable behavior and macros often do exactly the opposite: They create behaviors that exist in some places but not in other. This is counter-intuitive.

 

Finally, if the macro is long or complex, it will often push QlikView into an unstable situation. We have often seen this in documents sent to our support organization. The reason is probably a poor fit between the synchronous, sequential execution of a macro and QlikView’s internal asynchronous, multi-threaded computation.

 

From a development perspective, the macro feature is a secondary functionality. In the development process, it will rarely get first priority when compared to the “native” functionality: I.e. in the choice between keeping macro functionality unchanged and improving the out-of-the-box functionality, the QlikView development team will often choose the latter. This means that you can get a changed macro behavior when you upgrade your QlikView installation.

 

Macro1.png

 

Some facts around macros:

 

  • Single-Threaded?
    Macros are in their nature sequential – i.e. in a way single-threaded. But this is not the same as saying that all calculations started by macros are single-threaded. For instance, if a macro makes a selection that causes a chart to be calculated, both the logical inference and the chart calculation are multi-threaded. As they should be.
  • Clears cache?
    No. A macro does not clear the cache. (Unless you use the macro in the picture above...)
  • Clears the Back-Forward stack?
    No. A macro does not clear the Back-Forward stack.
  • Clears the Undo-Redo stack?
    Yes, if the macro contains layout changes, the Undo-Redo stack will be cleared.

 

So, I strongly recommend you don't use macros, unless it is in a Desktop environment. And there they should be short and concise! On a server you should instead use Actions.

 

There is however one thing that may confuse the user more than macros. And that is Triggers. If a macro or an action is started from a nicely labeled button, then the user will understand what happens.

 

But if the macro instead is triggered by some other event, e.g. the changing of a variable value, we have a very different situation. Then you will most likely create a non-intuitive behavior.

 

Macros are Bad, but Triggers are Worse.

 

HIC

 

See also

The Key to Heaven

56 Comments
pover
Luminary Alumni
Luminary Alumni

I completely agree.  I hardly ever use actions either, but the one time I did use them extensively some years back, I remember having trouble understanding the sequence in which a list of actions were executed.  The ascend and descend buttons to order a list of actions gave me the impression the actions were executed sequentially, but I remember having trouble doing things like first selecting a value, then assigning a resulting value to a variable, then clearing the selection, and making a another selection based on the same variable all in one action list.  Any insight on how actions are executed?

0 Likes
4,624 Views
luciancotea
Specialist
Specialist

As usual, great article! I think there will be a lot of comments around it because macros are the most popular discussion topic.

Everybody is different and everybody wants to differentiate. Custom behaviors, custom data export, emails, custom software integration, time saving automation tasks... all possible with macros.

Yes, macros are bad, but it's the necessary evil.

BTW, any words on the QlikView NEXT API? How the new changes are going to affect the third party tools (like NPrinting, QV Mail,...)?

4,624 Views
richard_pearce6
Luminary Alumni
Luminary Alumni

It's a shame but unfortunately fact....

Macros can be very useful though, especially when actions don't give you the flexibility.

Adding bookmarks done via a macro allows you the define the bookmark. Why are these basic parameter settings missing from the inbuilt action.....?

0 Likes
4,624 Views
Not applicable

Henric, I use macro's to define functions in the load script for calculations that are not available with QV functions. For example when I need to a newton-raphson optimisation (iterative process). And offcourse in the user interface to export multiple charts at once. 

0 Likes
4,624 Views
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Henric, Completely agree with all your points here.  I often post responses on the Community stating that to do that you will need to use a Macro - so don't do it.

Triggers, when used sparingly, can be very useful - but I have seen some real train wrecks where the developer has set a bunch of selections on the On Tab Change event, totally confusing the users.

Steve

0 Likes
4,624 Views
hic
Former Employee
Former Employee

I agree with all of the above: Though BAD, macros are sometimes still necessary. And also I use them... However, I think it is important to set a base line - the initial approach must be not to use macros. They are the last resort.

@Richard Pearce: I agree. Actions should be able to do that.

@Mathias Vanden Auweele: You are right that you sometimes need to define your own functions - especially the iterative like Newton-Raphson, or to generate Poisson distributed random numbers (something which I have done using a macro function). I would just like to have another way than macros for that...

HIC

4,624 Views
Not applicable

Henric Cronström wrote:


I would just like to have another way than macros for that...

I agree!

0 Likes
3,840 Views
hic
Former Employee
Former Employee

Karl Pover If you have a list of actions (e.g. in a button) then the actions will be executed sequentially, as you would expect. However, there are some caveats:

  1. An action does not always wait for the previous action to finish. E.g. two selections in a row - the second selection will interrupt the calculation of the first, just as two clicks in the UI.
  2. Variables are assigned to the entire list, before the first action is executed. So, you cannot calculate a variable in one step and then re-use it in a later step. The reason is that the action is executed on the client, but the variable is assigned on the server, so a list of actions would be much too "chatty" if we had assigned the variables before each action.

HIC

3,840 Views
brian_booden
Partner Ambassador
Partner Ambassador

Steve,

There's nothing worse than an app full of OnChange triggers that reset selections when changing tabs.  That's the worst.  Triggers do have their place, but also need to be used with caution, especially from a navigational perspective.

Macros might provide extra functionality on occasion, but most of the time, i completely rule them out from the off due to compatibility issues with Ajax, as HIC rightly pointed out.  Most of the implementation we do nowadays are deployed using the Ajax client, so macros are just a no-go area in this regard.

Brian

3,840 Views
brian_booden
Partner Ambassador
Partner Ambassador

Henric Cronström, thanks for stating this explicitly.  I have seen this behaviour several times with button Actions, and always wondered if i was doing something wrong when the Actions appeared to be triggering out of order, or even more confusingly, in a random order.  In future i'll just try an alternative method, rather than squeezing all the actions into one button!

0 Likes
3,840 Views