Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Any chance you could add a msgbox or some other logging to the sub to see if it actually getting invoked when you don't expect it?

A bit of un-useful humor. You said "It is only triggered on an OnInput sequence for an input box.". The closing line of this thread's original blog post (which we may have strayed far from) is:

"Macros are Bad, but Triggers are Worse"

0 Likes
598 Views
Not applicable

Henry, Andy, all: Great comments about using macros, very useful for developers using QV macros for the first time.

What about exporting data to a custom XML using a macro? in a desktop environment?

If I understand well this is a "safe practice" using macros, is that correct?

Thanks!

0 Likes
598 Views
tobias_klett
Partner - Creator II
Partner - Creator II

Hello Henric,
you wrote: "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."

So I have a simple question: Are there any macros (not QV Action,...) that are running on AJAX?
Regards

Tobias

598 Views
hic
Former Employee
Former Employee

There are many macro methods that work also when launched from the Ajax client, but they are all executed server-side, which sometimes means a potential security problem.

HIC

0 Likes
598 Views
Jason_Michaelides
Luminary Alumni
Luminary Alumni

HIC,

I recently discovered (by accident!) the special script variable "ForceBackEndMacroExecution".

If I set this to 1, will it force all macros executed by a user using IE Plugin to run on the server?  The definitions of 1 (Always execute macros in back end) and 0 (Execute macros in front end for clients that support it) would seem to indicate this would be the effect but I wondered if you knew for sure?

I ask as we recently tested something that cycled through and selected field values in turn. In the AJAX client it worked well but in IE Plugin it was very slow. We concluded the latency was due to having to go back and forth between client and server each time as macros were being executed on the client for plugin and server-side for AJAX. (I hasten to add we didn't want to use a macro at all and have found another way to achieve our goal!)

Thanks,

Jason

601 Views
CYRUS
Contributor III
Contributor III

Hello Henric,

  I have an application in Qlikview which would be run as server application(Not desktop). 

The portion that i used macro was regular expression functionality.

As Qlik doesn't support Regular expression and i had several criteria that couldn't implement it with Qlik, I decided to use macro.

But I am using macro in my script not in my user interface.

Should I be worry about using it or activating "running unsafe macro and script" in QMC?

Thanks in advance,

Cyrus

 

0 Likes
517 Views