Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Retrieving Groups and their contents via API

Hi all,

My end goal is to be able to set a cycle button, via the API, so that when I automate the production of static charts (I know...), I can change some of the aspects of the charts.

So far, I've got a fairly decent program, written in C#, that uses the API to get hold of valid values for a selection of Fields, get the charts in the Qlikview file, and allow the user to specify a set of filters (built up from the Fields) against charts, and export an image to a jpg. It works a charm right now, but there are some charts where I need to flip a cycle button.


So I thought I'd start by simply retrieving the Groups collection, and take a look at what we've got. I should know now that collections don't happen in the API!

The SDK gives the following code:

groups=ActiveDocument.GetGroups

groups(0).AddField "Account"

Of course, writing this in .NET, I need to type groups; at the moment ActiveDocument.GetGroups returns an object. The SDK says that this object is a variant, of which there is no equivalent in .NET, and I have no idea how I get to the different elements of this array!

Any help gratefully appreciated.

Tom


1 Solution

Accepted Solutions
Not applicable
Author

** Caveat: This will only work if the groups are changed when the document opens, and not again, although it might be possible to advance through groups, but synchronisation might be a problem **

The way I found to do this, and it's not great, because it is like going through the cycle buttons blind, is as follows:

You can always access the labels collection of the group, thus:


IGroupProperties gp = doc.GetGroup(groupName).GetProperties();
object[] lbls = (object[])gp.Labels;




Based on the fact that when the Qlikview file opens every group is set at the first field in the group, and the label collection is in the same order, we should be able to loop through the labels, checking whether the label text matches the field we want, and then mimicking a click on the cycle button if it's not.



for (int i = 0; i < lbls.Length; i++)
{
if (lbls[ i ].ToString() == labelMatch)
{
return;
}
doc.GetGroup(groupName).Cycle(1);
}


Like I say, it's not a perfect solution; I'd like to be able to cycle through until I could be sure the active field was the field in question. I guess what I'm looking for is an GetActiveLabel() method, or perhaps GetActiveExpression()...

View solution in original post

3 Replies
Not applicable
Author

OK, I'm a little further down the line, in that I can now get a list of the groups, thus (please excuse the hideous formatting!):

object[]g = (object[])doc.GetGroups(); //get an object array of the groups. Each one of the items is a Group


So my real goal here is to work out what the active field is in a group, and then cycle through the group until my required field is active. Now I can get at the groups, I can now make the process a bit more user-configurable (I know, they're basically doing what they'd do, but via the API, but they do this bit once, and it applies across every combination of things they want to produce static charts for!)

For my next trick, I thought I'd wander through the groups collection, and find my group. I realise this is as easily achieved by doing doc.GetGroup(groupName), but I've had no joy with that either...


Groupgg ;
Fieldff ;
for(int i = 0; i < g.Length; i++)
{
gg = (Group)g[ i ]; //cast the element in question to type Group
if(gg.Name == groupName)
{
ff = gg.GetActiveField(); //THIS DOESN'T DO ANYTHING! IT RETURNS null!
}
}


So now I'm off to find out whether it's the group I've chosen to examine, or a method that simply doesn't do anything. I'm betting on the latter...

Wish me luck. I'm sure going to need it.

Tom

Not applicable
Author

Pretty straight-forward... If the group in question has any fields (or possibly just the active field) that is made up from an expression (such as building a value representing the values that go into that data point, for e.g.), rather than just plain old fields, it can't return the active field. I guess because it returns a value of type Field, which an expression doesn't count as?

Quite stumped now... I have an idea, but it's one of those based on a lot of assumption at runtime. I'll report back once I've implemented it.

Not applicable
Author

** Caveat: This will only work if the groups are changed when the document opens, and not again, although it might be possible to advance through groups, but synchronisation might be a problem **

The way I found to do this, and it's not great, because it is like going through the cycle buttons blind, is as follows:

You can always access the labels collection of the group, thus:


IGroupProperties gp = doc.GetGroup(groupName).GetProperties();
object[] lbls = (object[])gp.Labels;




Based on the fact that when the Qlikview file opens every group is set at the first field in the group, and the label collection is in the same order, we should be able to loop through the labels, checking whether the label text matches the field we want, and then mimicking a click on the cycle button if it's not.



for (int i = 0; i < lbls.Length; i++)
{
if (lbls[ i ].ToString() == labelMatch)
{
return;
}
doc.GetGroup(groupName).Cycle(1);
}


Like I say, it's not a perfect solution; I'd like to be able to cycle through until I could be sure the active field was the field in question. I guess what I'm looking for is an GetActiveLabel() method, or perhaps GetActiveExpression()...