Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello fellow developers, I have a question about how to reproduce a QS behavior using the Engine API / .NET SDK.
When interacting with a Qlik Sense app using the browser, we can apply "custom" selections that are not tied to a specific app field, but instead use a custom expression, like this:
In this case, as you can see, we're applying a selection to the calculated expression Year([SomeField]), but the question applies to any expression.
In the browser this can be done in a variety of ways, for example by creating a Filter Pane object and setting the custom expression we want to filter as its Dimension, or by clicking on a cell in a table that has the custom expression as one of its dimensions.
What I want to do is apply a selection to a custom expression like that using the .NET SDK (in other words: the Engine API). Is it possible? What is the easiest way to accomplish this?
I found out that you can user the .SelectHypercubeValues() method of a GenericObject, however this requires referencing a specific (and already existing) object. Can it be done some other way? I would like not having to rely on an already existing object in the app, since I want the method I'm implementing to work on any app.
Yes. exactly. Create a session object and put a ListObjectDef property in it! That's what the client does when you press that search icon in a visualization. That part works also for analyzer licenses, otherwise you wouldn't be able to search in visualizations!
I've never used that endpoint myself so I'm not 100% sure how it works, but I think you need to call the method "AcceptListObjectSearch" to "commit" your selection. There is an example of how this works here:
I think it's this endpoint you are looking for: https://help.qlik.com/en-US/sense-developer/August2021/Subsystems/EngineJSONAPI/Content/service-gene...
Or for the .NET version: https://help.qlik.com/en-US/sense-developer/August2021/Subsystems/NetSDKAPIref/Content/Qlik.Engine.I...
Thanks for the info, however this still requires having an existing ListObject to work with, while I wanted to write a more generic method. Should my approach be creating a ListObject on the fly? I see there's a "CreateGenericSessionObject" method, I assume that might work? Can it be invoked with an analyzer license, since it is temporary and not really editing the app? Or does it still require Professional access?
Yes. exactly. Create a session object and put a ListObjectDef property in it! That's what the client does when you press that search icon in a visualization. That part works also for analyzer licenses, otherwise you wouldn't be able to search in visualizations!
Thanks, I will try this approach.
@Øystein_Kolsrud well, I've been trying this, but I'm having no luck, maybe you will be so kind to help me out again 😅
I've written this code, as best I could based on your suggestions:
Listbox listBoxObj = app.CreateGenericSessionObject(new ListboxProperties()
{
ListObjectDef = new ListboxListObjectDef()
{
Def = new ListboxListObjectDimensionDef { FieldDefs = new string[] { "my custom field expression" } },
InitialDataFetch = new NxPage[] { new NxPage { Height = 10000, Left = 0, Top = 0, Width = 1 } },
},
Info = new NxInfo() { Type = "listbox" }
}) as Listbox;
listBoxObj.SearchListObjectFor("/qListObjectDef", "search expression");
However, the SearchListObjectFor() method this seems to do absolutely nothing.
I know the listbox is correctly defined and the selections are working, because if I select directly using the element number, like this:
listBoxObj.SelectListObjectValues("/qListObjectDef", new[] {1}, false);
selections work and I can see them reflected in the frontend. But with the expression-based search I'm having no luck.
Any ideas?
Note that I've used "ListboxProperties/ListboxListObjectDimensionDef " for the definition, because I couldn't find a way to use ListObjectDef directly, maybe that's the problem?
I've never used that endpoint myself so I'm not 100% sure how it works, but I think you need to call the method "AcceptListObjectSearch" to "commit" your selection. There is an example of how this works here:
And using the Listbox class here should be just fine, but if you want to avoid the client classes, then you'll find an example on how to only use the engine namespace for this here:
That example shows how to add a hypercube to a GenericObjectProperties instance, but it's the same thing for ListObject-instances apart from the name of the property which needs to be "qListObjectDef" if you're adding a list object.
Thanks, that was the missing piece, it works now 👍