Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

amien
Valued Contributor

sample how to read all the master items using SDK and C#

anyone got an example for me in c# or point me in the right direction?

1 Solution

Accepted Solutions
Employee
Employee

Re: sample how to read all the master items using SDK and C#

There is a public example for traversing apps and retrieving master objects using the .NET SDK.

https://github.com/AptkQlik/PublicExamples/tree/master/AppTraverser

9 Replies
Employee
Employee

Re: sample how to read all the master items using SDK and C#

There is a public example for traversing apps and retrieving master objects using the .NET SDK.

https://github.com/AptkQlik/PublicExamples/tree/master/AppTraverser

amien
Valued Contributor

Re: sample how to read all the master items using SDK and C#

Thanks!

amien
Valued Contributor

Re: sample how to read all the master items using SDK and C#

This didn't quite work afterall .. it works fine on the LicenseMonitor app and the Operational app .. but when i create in a new all some master items .. they wont show. any idea why this is?

Employee
Employee

Re: sample how to read all the master items using SDK and C#

Sounds to me like this is the method you are looking for: AppExtensions.GetMasterObjectList Method

amien
Valued Contributor

Re: sample how to read all the master items using SDK and C#

can you elaborate a bit?

Qlik.Sense.Client.IMasterObjectList masterobjects = Qlik.Sense.Client.AppExtensions.GetMasterObjectList(app);

This .. and then what? How do i loop though the objects?

Employee
Employee

Re: sample how to read all the master items using SDK and C#

Once you have the IMasterObjectList instance, you can access the information about which master objects are available from the layout of the list. To get the layout, you would do like this:

var listLayout = masterObjectList.GetLayout().As<MasterObjectListLayout>();

Then the set of object IDs for the master objects are available from this property: MasterObjectListLayout.AppObjectList Property

Those IDs can in turn be used to get the actual objects using the "GetObject" method from the app. So the full code would probably look something like this:

var masterObjectList = app.GetMasterObjectList();

var listLayout = masterObjectList.GetLayout().As<MasterObjectListLayout>();

var objectIDs = listLayout.AppObjectList.Items.Select(item => item.Info.Id);

var objects = objectIDs.Select(id => app.GetObject<GenericObject>(id));

Or, if you prefer, you could use the "Items" shortcut on the masterObjectList object to avoid having to explicitly go through the layout. (You will go through the layout anyway, but it will be taken care of in the background.) In that case the code would look like this:

var masterObjectList = app.GetMasterObjectList();

var objectIDs = masterObjectList.Items.Select(item => item.Info.Id);

var objects = objectIDs.Select(id => app.GetObject<GenericObject>(id));

ichimiike
New Contributor III

Re: sample how to read all the master items using SDK and C#

Hi there...

I've tried your solution but the AppObjectLlist always comes back with a Count of 0.

As a bit of background on what I'm trying to achieve:

I have several apps... with 100+ master dimensions / measures each. Essentially, I want a ist of each master item along with its description.

Any help will be gratefully received

Ta in advance,

Mat

Employee
Employee

Re: sample how to read all the master items using SDK and C#

The MasterObjectList will only contain references to generic objects. If you want to list master dimensions and measures, then you need to use these methods instead:

https://help.qlik.com/en-US/sense-developer/April2018/apis/net+sdk/html/M_Qlik_Sense_Client_AppExten...

https://help.qlik.com/en-US/sense-developer/April2018/apis/net+sdk/html/M_Qlik_Sense_Client_AppExten...

ichimiike
New Contributor III

Re: sample how to read all the master items using SDK and C#

Thanks for this... but as it happens, I posted the question and then worked it out for myself :-D

Listing master items using .NET SDK

Nice to see I got the same solution as you proposed though

Community Browser