Bug report #22120
Field_name in actions
Status: | Open | ||
---|---|---|---|
Priority: | Low | ||
Assignee: | - | ||
Category: | Actions | ||
Affected QGIS version: | 3.4.8 | Regression?: | No |
Operating System: | Windows 10 | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 29933 |
Description
(tested on QGIS 3.4.8 on Windows 10)
Actions in field scope have three variables: field_index, field_name, field_value.
Field_name doesn’t work when actions run from attribute table.
For example the following python action (in field scope):
from qgis.PyQt import QtWidgets
expr = '"[% @field_name ]"' + ' = ' + "'[ @field_value ]'"
QtWidgets.QMessageBox.information(None, "[ @field_name %]", expr)
works good from Identify Result panel, but when the action run from the attribute table it doesn’t show the name of the field.
A workaround is using the field index:
layer = QgsProject.instance().mapLayer('[% @layer_id ]')
field_name = layer.fields().field([ @field_index %]).name()