Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
ozcano
Contributor III
Contributor III

Traverse an qlik sense app to extract data from cell.Type of container using .NET SDK

Hello

Using .NET SDK (Qlik.Engine), I am trying to traverse an qlik sense app to extract data from cell.Type of container that has any tables in it. Here are the basic steps

Usings:

using Qlik.Sense.Client.Visualizations;
using Qlik.Engine;
using Qlik.Sense.Client;

Connection:

ILocation location = Qlik.Engine.Location.FromUri(uri);

location.AsNtlmUserViaProxy( loginCredentials: new NetworkCredential(user, pwd, domain),certificateValidation:false);

var hub = location.Hub()

Open particular App and get sheets:

IApp app = hub.OpenApp("87d72c24-2476-4855-9044-0cc1c4391931");
IList<ISheet> sheets = (IList<ISheet>)app.GetSheets();

Traverse::

foreach (ISheet sheet in sheets)

      foreach (SheetCell cell in sheet.Layout.Cells)

Get generic object:

GenericObject genericObject = app.GetGenericObject(cell.Name);

Get the measures by assigning the generic object to actual object type (by making use of https://github.com/AptkQlik/PublicExamples/tree/master/AppTraverser😞

ozcano_0-1707380404756.png

The problem is that, there is no Container object in the Qlik Sense .NET SDK to assign the generic object, if it is a container. The aim is to get the tables inside that container and then SerializeMeasures inside each table. But first I need get to the container.

Is there a solution for that?

Regards, Ozcan

NOTE: The reason I want to get measures is that to check whether I correctly migrated all old qlik view apps into new qlik sense apps.

Labels (1)
  • API

1 Solution

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

That traversal example is a little cumbersome as it gets the layout of all the sheet items. If you are just looking for objects of table type then there is a much simpler way to do that. The engine API has a method called "GenericObject::GetFullPropertyTree" which is great for this kind of traversals. That gives you the full object tree structure in one single call so that you don't have to open all the objects. The method returns a "GenericObjectEntry" structure, and you can get all the individual "GenericObjectProperties" instances from that very easily like this:

private static IEnumerable<GenericObjectProperties> GetAllProps(GenericObjectEntry entry)
{
    return entry.Children.SelectMany(GetAllProps).Append(entry.Property);
}

And with that method in place, you can get all the tables in a sheet like this:

private static IEnumerable<GenericObjectProperties> GetTables(IGenericObject sheet)
{
    var propTree = sheet.GetFullPropertyTree();
    var allProps = GetAllProps(propTree);
    return allProps.Where(p => p.Info.Type == "table");
}

 So now, if you for instance want to simply print the ID of all tables in all sheets of an app, then you can do like this:

using (var app = location.App(appId))
{
    foreach (var table in app.GetSheets().SelectMany(GetTables))
    {
        Console.WriteLine(table.Info.Id);
    }
}

 Hope that helps!

View solution in original post

1 Reply
Øystein_Kolsrud
Employee
Employee

That traversal example is a little cumbersome as it gets the layout of all the sheet items. If you are just looking for objects of table type then there is a much simpler way to do that. The engine API has a method called "GenericObject::GetFullPropertyTree" which is great for this kind of traversals. That gives you the full object tree structure in one single call so that you don't have to open all the objects. The method returns a "GenericObjectEntry" structure, and you can get all the individual "GenericObjectProperties" instances from that very easily like this:

private static IEnumerable<GenericObjectProperties> GetAllProps(GenericObjectEntry entry)
{
    return entry.Children.SelectMany(GetAllProps).Append(entry.Property);
}

And with that method in place, you can get all the tables in a sheet like this:

private static IEnumerable<GenericObjectProperties> GetTables(IGenericObject sheet)
{
    var propTree = sheet.GetFullPropertyTree();
    var allProps = GetAllProps(propTree);
    return allProps.Where(p => p.Info.Type == "table");
}

 So now, if you for instance want to simply print the ID of all tables in all sheets of an app, then you can do like this:

using (var app = location.App(appId))
{
    foreach (var table in app.GetSheets().SelectMany(GetTables))
    {
        Console.WriteLine(table.Info.Id);
    }
}

 Hope that helps!