Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
master_t
Partner - Creator II
Partner - Creator II

Filtering by a custom expression using the Engine API?

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:

master_t_0-1632826168895.png

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.

Labels (4)
2 Solutions

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

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!

View solution in original post

Øystein_Kolsrud
Employee
Employee

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:

https://help.qlik.com/en-US/sense-developer/August2021/Subsystems/EngineAPI/Content/Sense_EngineAPI/...

View solution in original post

8 Replies
master_t
Partner - Creator II
Partner - Creator II
Author

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?

Øystein_Kolsrud
Employee
Employee

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!

master_t
Partner - Creator II
Partner - Creator II
Author

Thanks, I will try this approach.

master_t
Partner - Creator II
Partner - Creator II
Author

@Ø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?

 

Øystein_Kolsrud
Employee
Employee

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:

https://help.qlik.com/en-US/sense-developer/August2021/Subsystems/EngineAPI/Content/Sense_EngineAPI/...

Øystein_Kolsrud
Employee
Employee

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:

https://github.com/kolsrud/qlik-dot-net-sdk-hypercube-usage/blob/master/HypercubeUsage/Program.cs#L5...

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.

master_t
Partner - Creator II
Partner - Creator II
Author

Thanks, that was the missing piece, it works now 👍