Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
Let's say I have the following engine API request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "CreateSessionObject",
"handle": 1,
"params": [
{
"meta": {
"data": "this is the data",
"qValueExpression": "=COUNT(CategoryName)"
},
"qInfo": {
"qId": "",
"qType": "Listbox"
},
"qListObjectDef": {
"qInitialDataFetch": [
{
"qTop": 0,
"qLeft": 1,
"qHeight": 1,
"qWidth": 1
}
]
}
}
]
}
How could I do something similar with the .NET SDK? I've got an open session, and an IApp instance
Thanks and regards,
Shane.
Hi,
attached is a complete example that works with Qlik Sense Desktop1.0.0.0.
If you create an console application called CustomObject and replace program.cs. After adding the references til Qlik Sense .Net SDK 1.0.0.0 you shold be able to test the solution.
Note that I have added another custom property "title" that is an StringExpressionContainer where you can set expressions like "=Count(Dim2)".
PS don't forget to start QlikSense.exe
Best regards
Lars-Göran Book
Can anyone help me with this one please? Thanks, and a Happy New Year to you all.
Hi Shane,
The App object has a method CreateGenericSessionObject which you can use to create session objects. It takes a parameter of GenericObjectProperties. I would suggest that you create a set of classes for your object :
MyObjectProperties, MyObjectLayout and MyObject.
The MyObjectProperties should inherit from GenericObjectProperties and to this object you can add your custom properties.
public class MyObjectProperties : Qlik.Engine.GenericObjectProperties
{
public Qlik.Engine.ListObjectDef qListObjectDef
{
get { return this.Get<Qlik.Engine.ListObjectDef>("qListObjectDef"); }
set { this.Set("qListObjectDef", value); }
}
}
The MyObjectLayout should inherit from GenericObjectLayout which describes the rendered object (layout).
public class MyObjectLayout : Qlik.Engine.GenericObjectLayout
{
public Qlik.Engine.ListObject qListObject
{
get { return this.Get<Qlik.Engine.ListObject>("qListObject"); }
set { this.Set("qListObject", value); }
}
}
The MyObject should inherit from GenericObject, this class holds properties and layout for the object. To this class you can later add support for paging, selections etc.
public class MyObject : Qlik.Engine.GenericObject, System.IDisposable
{
public MyObject(int handle) : base(handle)
{
}
public new MyObjectProperties Properties
{
get { return ((MyObjectProperties)(base.Properties)); }
set { base.Properties = value; }
}
protected new MyObjectLayout Layout
{
get { return ((MyObjectLayout)(base.Layout)); }
}
private bool _disposed;
#region IDisposable methods
protected override void Dispose(bool disposing)
{
if (this._disposed)
{
return;
}
this._disposed = true;
base.Dispose(disposing);
}
#endregion
}
To create a object create your properties and call CreateGenericSessionObject.
var prop = new MyObjectProperties
{
Info = { Id = "TheBest", Type = "mylistbox" },
qListObjectDef = new ListObjectDef
{
Def = new NxInlineDimensionDef { FieldDefs = new string[] { "Dim2" } },
InitialDataFetch = new NxPage[] {new NxPage{ Height = 100, Left = 0, Top = 0, Width = 1}}
}
};
var mylb = (MyObject)App.CreateGenericSessionObject(prop);
On the created object call GetLayout to get the rendered information
var l = (MyObjectLayout)mylb.GetLayout();
And now you can access the the data/properties within the object
var datapages = l.qListObject.DataPages
Best regards
Lars-Göran Book
Hi,
thanks for the detailed reply!
Unfortunately, the MyObjectProperties and MyObjectLayout classes (inheriting from GenericObjectProperties and GenericObjectLayout respectively) don't have a definition for 'Get' and 'Set', and so I get a compilation error.
I'm using 1.0.0.0 of the Qlik.Engine.dll.
Thanks,
Shane.
Hi,
attached is a complete example that works with Qlik Sense Desktop1.0.0.0.
If you create an console application called CustomObject and replace program.cs. After adding the references til Qlik Sense .Net SDK 1.0.0.0 you shold be able to test the solution.
Note that I have added another custom property "title" that is an StringExpressionContainer where you can set expressions like "=Count(Dim2)".
PS don't forget to start QlikSense.exe
Best regards
Lars-Göran Book
Thank you!
Just one thing though - how do I actually evaluate the expression (=Count(Dim2) for example)? I see the data for the dimension as a result of GetLayout() call.
Just not sure how to get the expression result.
Thanks,
Shane.
With the properties you set the expression for example "=Count(Dim2)" and in the layout (that is when the object is rendered) you will get the result of the expression in this case 6.
With client objects such as Barchart the SDK give you the layout as you access (use) thier properties such as the title, not that this is lazy. This is probably why you havent seen the GetLayout() call before, when you create your own objects you will have to decide what functionality you wan to implement.
// Lars-Göran Book