6

Using the new @alg decorator structure I am trying to populate a drop down with the fields (attributes in a table).

Using the code in https://docs.qgis.org/3.22/en/docs/user_manual/processing/scripts.html#the-alg-decorator

I have

@alg(name='searchupdatealg', label='Search and update (alg)',
     group='mgm', group_label='Example scripts')
# 'INPUT' is the recommended name for the main input parameter
@alg.input(type=alg.SOURCE, name='INPUT', label='Input vector layer')
@alg.input(type=alg.FIELD, name='Attrib', label='Attribute')
# 'OUTPUT' is the recommended name for the main output parameter

Looking at older code as in http://www.qgistutorials.com/fi_FI/_images/8b.png

It looks like we have to get the fields and put them into the list -but how is this done when we have @alg.input(type=alg.FIELD ...

1 Answer 1

6

No need to put the fields into the parameter's combobox manually. Just add parentLayerParameterName='INPUT' to @alg decorator.

@alg.input(type=alg.SOURCE, name='INPUT', label='Input vector layer')
@alg.input(type=alg.FIELD, name='Attrib', label='Attribute',
           parentLayerParameterName='INPUT')

There is no explanation about this in QGIS Processing Script Documentation. But the parameter name comes from the constructor method of QgsProcessingParameterField.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.