<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi,</p>
<p>I am trying to implement a Python action in "form" and "feature" action scope that uses a QGIS expression, but fail to get a valid expression calculation.</p>
<p>Here is my code so far:</p>
<p><span style="font-family: courier new, courier, monospace;">from qgis.PyQt.QtWidgets import *</span><br /><span style="font-family: courier new, courier, monospace;">from qgis.core import QgsMessageLog</span></p>
<p><span style="font-family: courier new, courier, monospace;">expContext = QgsExpressionContext()</span><br /><span style="font-family: courier new, courier, monospace;">expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))</span><br /><span style="font-family: courier new, courier, monospace;">expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))</span></p>
<p><span style="font-family: courier new, courier, monospace;">exp = QgsExpression('t_id')</span></p>
<p><span style="font-family: courier new, courier, monospace;">expResult = exp.evaluate(expContext)</span><br /><span style="font-family: courier new, courier, monospace;">QgsMessageLog.logMessage('Expression Result=' + str(expResult))</span></p>
<p><br /></p>
<p>So even the most basic expression (getting a field value) will not work in my code. I always get "None" as a result.</p>
<p>Any idea what is missing? Am I missing a certain scope or an import statement?</p>
<p>Thank you very much for any hints what might be wrong here ...</p>
<p>Andreas</p>

</body></html>