Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
mel78
Contributor II
Contributor II

QlikSense .NET SDk: how to retrieve filtered data from a table?

I am using a QLIK table within a sheet. It has 20 records. The user filters the data now and it has 5 records now.

Can I use QLIK API from .net to get this 5 records? I am able to get 20 records using genericObject.GetHyperCubeData methods, but not sure it is possible to get filtered data?

If this is possible, can I get filtered data for any object (pivot-table, filter-pane etc) ?

 

Labels (3)
12 Replies
Øystein_Kolsrud
Employee
Employee

Selections only exists with a session, so to make selections visible for your SDK access, you need to make sure you connect to that same session as the one the user was connected to when doing the filtering. This is a related thread here on Community that might be of interest to you:

https://community.qlik.com/t5/Qlik-Sense-Integration/NET-SDK-Sharing-session/m-p/1520370

An example of how to connect to the session used by the Qlik Sense Client can be found in this comment:

https://community.qlik.com/t5/Qlik-Sense-Integration/NET-SDK-Sharing-session/m-p/1520370/highlight/t...

 

mel78
Contributor II
Contributor II
Author

I am able to connect to Qlik, but unable to see the same data that the user can see. Can you please guide me to any code sample that I see?

I tried using AsNtlmUserViaProxy and AsDirectConnection. I am also attempting setting cookies , but no success.

location.CustomUserCookies.Add("X-Qlik-Session-dev", "XXXXXX");

Øystein_Kolsrud
Employee
Employee

You'll have to connect through the proxy to be able to share session with the Qlik Sense client, so a direct connection won't work.

If you post the code you use for doing the connection then perhaps we might be able to identify if there is anything missing.

mel78
Contributor II
Contributor II
Author

See below the code I have. 

I am able to get rowCount = 21. But I am looking for rowCount = 3 because I applied the filters on a partcular field. This means that the .Net client is unable to share the same session as the web browser.

 

private static ILocation SetupConnection()
{

_qlikSenseServerUri = new Uri("https://qlik.myserver");

ILocation location = Location.FromUri(_qlikSenseServerUri);

location.AsNtlmUserViaProxy(true, null, false);

return location;
}

 

private HttpResponseMessage GetQlikData(ILocation location)
{
try
{

IAppIdentifier appId = location.AppWithIdOrDefault("1786433e-8c76-4c24-a21d-2d51c9888ba0");
ISession session = Session.WithApp(appId, SessionType.Default);
IHub hub = LocationExtensions.Hub(location, session);
App app = hub.OpenApp(appId.AppId);


var extendedCurrentSelection = app.GetExtendedCurrentSelection();
foreach (var field in extendedCurrentSelection.FieldNames)
{
Console.WriteLine("Field: " + field);
IEnumerable<NxDataPage> mypages = extendedCurrentSelection.GetSelectedData(field, new[]
{
extendedCurrentSelection.Size(field).AsPage(100)
});
foreach (var dataPage in mypages)
{
Console.WriteLine("Selected value : " + dataPage.AllCells().Select(cell => cell.Text));
}
}

var objectList = app.GetObjects(new NxGetObjectOptions() { IncludeSessionObjects = true, Types = new List<string>() { "table" } });


var genericObject = app.GetGenericObject("YpBmJAY");

var cellsPage = new NxPage { Top = 0, Height = 100, Left = 0, Width = 100 };


IEnumerable<NxDataPage> pages = genericObject.GetHyperCubeData("/qHyperCubeDef", (new[] { cellsPage }));
var rows = pages.FirstOrDefault().Matrix;


int rowCount = rows.Count();

}

catch (CommunicationErrorException cex)
{
Console.WriteLine("Can not connect to Qlik Sense instance, check that Qlik Sense is running." + Environment.NewLine + cex.Message);
}
catch (Exception ex)
{
Console.WriteLine("General error." + Environment.NewLine + ex.Message);
}
return null;
}

Øystein_Kolsrud
Employee
Employee

Are you using .Net Core or .Net Framework? I think there was an issues with the session setup in the .Net Core version that was fixed recently, so if you are using .Net Core then you might want to see if it works for you using .Net Framework. The fix should be out in the next release of the SDK.

mel78
Contributor II
Contributor II
Author

I am using .Net framework not Core. Can you please review my code and see what I am missing?  It is always creating a new session and not use a existing one.

Øystein_Kolsrud
Employee
Employee

I tried the code and (modifying the IDs obviously) it works just fine. I can see the selections I do in the client through those calls. The only error I saw in the code was that you are printing the cell rows enumerable directly instead of concatenating it into a string first, but I assume that is not the issue you are seeing.

Are the selections you do in the client getting cleared when you run your program? Perhaps you have "extended security environment" enabled on your virtual proxy?

mel78
Contributor II
Contributor II
Author

Are you using Google chrome? the selections still stay there and is not cleared.  I will check regarding "extended security environment"

 

mel78
Contributor II
Contributor II
Author

I checked. Extended security environment is unchecked on the virtual proxy. Just to be clear. I am trying to make changes on the chrome web browser and see those same changes on the .net side.