I am trying to use select by expression in QGIS graphical modeler and use an input string as value inside the expression.
So the model will ask the user for input (which value) and this should then be used in the algorithm.
The thing is, if I write the expression in the model, then the algorithm does work:
"gemnaam" ILIKE 'A%' does select all features with attribute gemnaam starting with an A.
If I use "gemnaam" ILIKE @firstchar no features are selected.
Now, when I use Extract by expression in stead, this algorithm does work with @firstchar
Is it a bug or default behaviour that Select by expression does not work with variable user input like @firstchar?
Best Answer
If you want to define an input as a variable, first create an input, than use this input with
Set project variable
, give it a name and use the value of the input withUsing model input
(see screenshot).You can than use this variable with it's name in select by expression. Be sure that in the
Select by expression
dialog box (bottom left on the screenshot) underDependencies
you have selected theDefine variable
algorithm. Otherwise, you have to run the model twice to update the variable to the new input.Running the model with input character
a
: all features with attributename
starting witha
are selected:If you have a pre-defined project-variable, this solution applies:
You forgot the '%' part. Use this expression:
Or use this alternative: