Qlikview Developer Macros

1When I am designing a Qlikview application, I often create a sheet that is essentially a draft area. It’s a place where I can drop text boxes, list boxes, and all manner of items that have nothing to do with the actual dashboard. This sheet is just for me to run tests and validations; I will hide it once the document goes into publication so no user ever sees it. However it’s there when I need it.
One of the key things I create and reuse in this space are buttons that trigger helpful designer macros. These macros I use to clean up things in the designer side. A few examples that I will go into are centering labels and turning on/off the ability to move and copy objects.

Center Labels2

For nearly all the charts, straight tables, or pivot tables having the headers centered is standard. Now instead of going through and manually changing this one at a time, I use a macro that will do that for me and all I have to do is click the button to trigger that.

function centerLabels()
{
var doc = ActiveDocument;
var LabelAlignmentEnum = { LEFT:0, CENTER:1, RIGHT:2 };

// Loop over sheets
for (var i = 0; i < doc.NoOfSheets(); i++)
{
var sheet = doc.Sheets(i);

// Loop over sheet objects in sheet
for (var j = 0; j < sheet.NoOfSheetObjects(); j++)
{
var sheetObject = sheet.SheetObjects(j);
var props = sheetObject.GetProperties();

// Only look at objects with dimensions
if (“Dimensions” in props)
{
var dims = props.Dimensions;
var graphName = sheetObject.GetCaption().Name.v;

// Loop over dimensions in sheet objects in sheet
for (var k = 0; k < dims.Count; k++)
{
var dim = dims.Item(k);
if (“LabelAdjust” in dim)
{
var dimName = dim.PseudoDef.Name;
dim.LabelAdjust = LabelAlignmentEnum.CENTER;
}
}
sheetObject.SetProperties(props);
}
}
}
}

Enable/Disable Move, Size, Copy & Clone

3I often find myself having to go in and turn on or off the features in the layout properties for objects. Sometimes I want to make sure I don’t accidentally move or re-size something or I have everything turned off but now I have to move it all to make room for another button or chart. Two more buttons I use trigger macros that will loop through all the objects I’ve created and turn these options on (enableMoveSizeCopyClone) or off (disableMoveSizeCopyClone).

function enableMoveSizeCopyClone()
{
setMoveSizeCopyClone(true);
}

function disableMoveSizeCopyClone()
{
setMoveSizeCopyClone(false);
}

function setMoveSizeCopyClone(boolAllow)
{
var doc = ActiveDocument;

for (var i = 0; i < doc.NoOfSheets(); i++)
{
var sheet = doc.Sheets(i);

for (var j = 0; j < sheet.NoOfSheetObjects(); j++)
{
var sheetObject = sheet.SheetObjects(j);
var frame = sheetObject.GetFrameDef();

frame.AllowCopyClone = boolAllow;
frame.AllowMoveSize = boolAllow;
sheetObject.SetFrameDef(frame);
}
}
}

,

Comments are closed.