Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get data from exist object based on ID using .net SDK

Hi All,

    Here am stuck with .net SDK, am trying to get the data from existing object based on object ID, the code is

     private IApp qsApp;

     var GetApi = qsApp.GetAllInfos();

           

            foreach (var item in GetApi)

            {

                var ItemType = item.Type;

                var ItemID = item.Id;

                var masterObject = qsApp.GetObject<MasterObject>(ItemID); // here  want to get the KPI values

            }

this part returning the null value when pass the KPI id, if am did some mistake in this code part please correct me and suggest me is this good way to get the data's from existing one.

1 Solution

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

When you access kpiLayout1.HyperCube.DataPages like that, then you are accessing the data retrieved through the "initial data fetch" concept, which for a KPI is usually exactly what you want. Now you just want to extract the relevant values, and it looks to me like you are already on the right track there. There are a couple of levels you need to dig through though, as the DataPages configuration is a generic one, but for KPIs you are only interested in one single cell. You would retrieve the cell like this:

var theCell = kpiLayout1.HyperCube.DataPages.First().Matrix.First().First();

The translates into something like the first cell of the first row of the first page. And now that you have the cell, you can access the numeric and string representations of the value like this:

var num = theCell.Num;

var txt = theCell.Text;

View solution in original post

8 Replies
Øystein_Kolsrud
Employee
Employee

There are at least three questions hiding here:

  1. How do you identify which ID is associated with the object you are interested in?
  2. Given the correct ID, how do you retrieve it from the app given that it's a master object?
  3. Given that you have retrieved the object correctly, how do you access the KPI values?

Which one of these is it that you need help with?

Anonymous
Not applicable
Author

Hi Oystein Kolsrud

    Thanks for your replay, am expecting like 3th one (" Given that you have retrieved the object correctly, how do you access the KPI values? ")


Thanks

Øystein_Kolsrud
Employee
Employee

OK, does the ID represent the master object, or an object derived from it? If it's the latter, then you can access it just like if it's not based on a master object (I assume here that by KPI you mean that the object represents a Qlik Sense client AKPI object) and use the properties of the object accordingly, something like this:

var kpiObject = qsApp.GetObject<Kpi>(ItemID);

var pager = kpiObject.HyperCubePager;

You would basically be working with this class: Kpi Class

If, on the other hand, you are accessing the master object, then you should either use the abstract structure concept to interpret the layout of the object as a Kpi-layout, or use the generic GenericObject.GetAllHyperCubePagers Method to access the hypercube. So either like this:

var genericObject = qsApp.GetObject<GenericObject>(ItemID);

var kpiLayout = genericObject.GetLayout().As<KpiLayout>();

Or like this:

var genericObject = qsApp.GetObject<GenericObject>(ItemID);

var pager = genricObject.GetAllHyperCubePagers().Single();

Øystein_Kolsrud
Employee
Employee

You can find more information on the abstract structure concept here:

Abstract structure ‒ Qlik Sense Developers

And an example can be found here:

Abstract structure - enables dynamic data in a statically typed environment ‒ Qlik Sense Developers

Anonymous
Not applicable
Author

Hi Oystein Kolsrud,


    Thank you like this am excepting , i can't get the Text and Num values from {Qlik.Engine.NxCell} which available in debug mode.

                  var genericObject = qsApp.GetObject<GenericObject>(ItemID);

                    var kpiLayout1 = genericObject.GetLayout().As<KpiLayout>();

                    var kpiHyper = kpiLayout1.HyperCube.DataPages;

if you place cursor in kpiHyper in debug mode this one available in [0] {Qlik.Engine.NxDataPage} => Matrix => [0] Count =1 => [0] Qlik.Engine.NxCell, so popup will open in that i want Text and Num values.


How to get the values


Thanks

Anonymous
Not applicable
Author

Thanks for sharing

Øystein_Kolsrud
Employee
Employee

When you access kpiLayout1.HyperCube.DataPages like that, then you are accessing the data retrieved through the "initial data fetch" concept, which for a KPI is usually exactly what you want. Now you just want to extract the relevant values, and it looks to me like you are already on the right track there. There are a couple of levels you need to dig through though, as the DataPages configuration is a generic one, but for KPIs you are only interested in one single cell. You would retrieve the cell like this:

var theCell = kpiLayout1.HyperCube.DataPages.First().Matrix.First().First();

The translates into something like the first cell of the first row of the first page. And now that you have the cell, you can access the numeric and string representations of the value like this:

var num = theCell.Num;

var txt = theCell.Text;

Anonymous
Not applicable
Author

Thanks Oystein Kolsrud , i got it ...