Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
chrislemm
Partner - Contributor III
Partner - Contributor III

Make selection / set filter in Qlik Sense App via .NET SDK

Hello,

I'm currently developing an .NET App which should control a QS App (making selections/setting filters etc.).

I'm can read the current made selection in the tool live, which is great but I have troubles making selections via my app.

So my question is: How can I make a selection / set a filter on my app?

Like setting a Datefilter, a customer filter to a certain customer etc.?

Dim currentSelection As ICurrentSelection = myApp.GetCurrentSelection

For Each selectedField In currentSelection.Selections

MsgBox("Field: " & selectedField.Field & vbNewLine & "Selected Values: " & selectedField.Selected)

Next

Thank you and best regards

1 Solution

Accepted Solutions
konrad_mattheis
Luminary Alumni
Luminary Alumni

Hi,

this should help your:

myApp.GetField(fielname).Select(filtertext, true);

bye Konrad

View solution in original post

9 Replies
konrad_mattheis
Luminary Alumni
Luminary Alumni

Hi,

this should help your:

myApp.GetField(fielname).Select(filtertext, true);

bye Konrad

chrislemm
Partner - Contributor III
Partner - Contributor III
Author

Thank you for your reply. That was the solution. I have to admit I found out earlier but I did forgot about that post.

But I still have the problem to select multiple filters like f.e. years: 2016,2015 etc.

Can I only set a single filter?

konrad_mattheis
Luminary Alumni
Luminary Alumni

Hi,

it should work with filtertext = "2016 2015 2014" as example.

bye Konrad

chrislemm
Partner - Contributor III
Partner - Contributor III
Author

Not working for me . I tried 2016,2015 etc. -> delets my filter; 2016;2015 -> same; 2016|2015 -> same; 2016 2015 -> same.
I tried to pass a array to this function, also not working because the parameter is a simple string.

Best regards

konrad_mattheis
Luminary Alumni
Luminary Alumni

Hi,

than you have to go the "hard" way like.

CreateGenericSessionObject as Lisfbox,

Fetch the Data, mark the elements as filtered

Destroy the Object.

Just take chrome an watch the websocket connection

if you click on a filterbox in the currentselection and

change a filter setting.

bye Konrad

Øystein_Kolsrud
Employee
Employee

It sounds like you might want to have a look at this function that makes it possible to select multiple field values:

IField.SelectValues Method

Otherwise, there is this section in the documentation for the SDK that gives guidance on how to work with selections:

Filtering data with selections ‒ Qlik Sense

Best regards, Øystein Kolsrud

Øystein_Kolsrud
Employee
Employee

If you want to do something more advanced, like selecting ranges of values, then you might want to look into using the AppField concept instead:

http://help.qlik.com/en-US/sense-developer/3.1/apis/net%20sdk/html/T_Qlik_Sense_Client_IAppField.htm

http://help.qlik.com/en-US/sense-developer/3.1/Subsystems/NetSDKAPI/Content/WorkWith/Net-Sdk-Work-Wi...

An AppField is a generic object containing a ListObject for a particular filed. That allows you to use the selection mechanisms of generic objects for doing what you want. You can use this method to get an AppField for a particular field:

AppExtensions.GetAppField Method

The AppField object returned by that method provides methods for doing operations on the list box. For instance, this method can be used to select ranges:

http://help.qlik.com/en-US/sense-developer/3.1/apis/net%20sdk/html/M_Qlik_Sense_Client_IAppField_Sel...

catalin
Partner - Contributor III
Partner - Contributor III

Hi, I know its 4 years late, but I was looking for an answer and stumbled on your inquiry. 

Multiple values in the field values of a QS selection is an :

 

IEnumerable(Of FieldValue)

 

 Your best bet is to have a class, something like this:

 

Public Class QSSelection
        Public Property fieldname As String
        Public Property fieldvalues As IEnumerable(Of FieldValue)
End Class

 

And then you can pass the properties to this class (let's suppose you have a Date field in your QS app and you need to apply, let's say, 56 days in the past, starting from today, as selections:

 

Dim qs_selection as QlikSelection() = New QlikSelection()
qs_selection.fieldname = "Date" 
Dim today = DateTime.Now().Date
Dim firstday = today.AddDays(-56)
Dim datematrix As List(Of Date) = New List(Of Date)
Dim i As Integer
For i = 1 To 56
    datematrix.Add(today.AddDays(-i).ToShortDateString)
Next
qs_selection.fieldvalues = {New FieldValue With {.Text = Nothing, .Number = 0, .IsNumeric = True}}
For Each zi In datematrix    
    qs_selection.fieldvalues = qs_selection.fieldvalues.Concat({New FieldValue With {.IsNumeric = True, .Number = CType(zi.ToOADate, Integer), .Text = zi}})
Next

 

And from now on it's pretty simple as you can call the SelectValues() function of the IField interface and give it the IEnumerable(Of FieldValue) from your class. Something like this:

 

Public Sub ApplySelections(ByVal location As ILocation, ByVal id As IAppIdentifier, ByVal QSSelections As QlikSelection)
  Dim app = location.App(id)
  app.GetField(QSSelections.fieldname).SelectValues(QSSelections.fieldvalues)
End Sub

 

 

Hemik
Contributor II
Contributor II

Hi,

It's late response but it may help someone.

I was searching the solution for filters with multiple value using dotnet and I found the below solutions and It's working fine.

 

var fieldLst = new List<FieldValue>();
foreach (string account in accountArray)
{
          FieldValue fieldValue = new FieldValue();
          fieldValue.IsNumeric = false;
          fieldValue.Text = account;
          fieldLst.Add(fieldValue);
}
app.GetField(field).SelectValues(fieldLst, true);

 

Thanks,

Hemik