Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
berndpodhradsky
Partner - Contributor III
Partner - Contributor III

.NET SDK Get Visualization behind Master Item

Hi!

When querying master items from the SDK I am able to get items of type MasterItem. Is there any chance to get the actual i.e. Barchart object (if it's a barchart, for instance) from that master item (i.e. the same object I would get when calling GetGenericObject with the ID of an item that is actually displayed on a sheet)?

Thanks in advance,
Bernd

3 Replies
Øystein_Kolsrud
Employee
Employee

Assuming that you want to access the properties of the master object and treat them as bar chart properties, then you can convert the GenericObjectProperties to BarchartProperties using the "AbstractStructure.As" method like this:

using (var app = location.App(appId))
{
    var obj = app.GetGenericObject(objectId);
    var barchartProps = obj.Properties.As<BarchartProperties>();
    Console.WriteLine(barchartProps.BarGrouping.Grouping);    
}

More on the topic of AbstractStructure can be found here:

https://help.qlik.com/en-US/sense-developer/February2021/Subsystems/NetSDKAPI/Content/Sense_NetSDKAP...

An example focusing on the use of AbstractStructure in the .NET SDK can be found here:

https://github.com/AptkQlik/PublicExamples/blob/master/AbstractStructure/Program.cs

berndpodhradsky
Partner - Contributor III
Partner - Contributor III
Author

Hi!

Thanks - I was aware of the approach you mentioned. But I infer from your answer that converting the MasterItem to a Barchart object is not possible, correct?

To explain why I ask this: if we have a function that takes a Barchart object as parameter and does lots of things with that object and we want to extend this functionality to also support bar charts which have been added as master items, we have to rewrite the complete function, because we cannot get a Barchart object from the master item. Am I right?

Bernd

Øystein_Kolsrud
Employee
Employee

Yes, that is correct. A master object is not a barchart, but it can have properties describing a barchart. You could possibly use a linked object that extends the master object because that would be a barchart. Like this:

 

var props = new GenericObjectProperties
{
    Info = new NxInfo {Type = "barchart"},
    ExtendsId = objectId
};
var barchart = (Barchart) app.CreateGenericSessionObject(props);
Console.WriteLine(barchart.Properties.BarGrouping.Grouping);
app.DestroyGenericSessionObject(barchart.Id);

 

But the object will be read-only. If you want to modify it, then you have to go through the master item.