Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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:
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
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
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.