Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help converting Engine API Request to .NET API

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.

1 Solution

Accepted Solutions
Not applicable
Author

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

View solution in original post

8 Replies
Not applicable
Author

Can anyone help me with this one please?  Thanks, and a Happy New Year to you all.

Michael_Tarallo
Employee
Employee

Hi Shane - let me see if ewg or perhaps bmz can assist or find someone that can help.

Happy New Year too.

Mike T

Qlik

Regards,
Mike Tarallo
Qlik
Not applicable
Author

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

Not applicable
Author

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.

Not applicable
Author

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

Not applicable
Author

Thank you!

Not applicable
Author

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.

Not applicable
Author

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