I'm currently using QGIS 3.30 and I'm trying to set a default value for a field based on multiple other fields, without having the default value update automatically whenever an attribute of the feature is updated. The expression I'm using is as follows:
CASE
WHEN count("AID") = 0 THEN
regexp_replace(
upper(
concat(
coalesce(left(rpad("vorname", 1, 'X'), 3), 'X'),
coalesce(left(rpad("name", 1, 'X'), 3), 'X'),
coalesce(left(rpad("rolle", 1, 'X'), 3), 'X'),
lpad('1', 4, '0'),
@nis_project_id
)
),
'[^a-zA-Z0-9]',
'_'
)
ELSE
regexp_replace(
upper(
concat(
coalesce(left(rpad("vorname", 1, 'X'), 3), 'X'),
coalesce(left(rpad("name", 1, 'X'), 3), 'X'),
coalesce(left(rpad("rolle", 1, 'X'), 3), 'X'),
lpad(
to_string(
maximum(to_int(substr("AID", 4, 4))) + 1
),
4,
'0'
),
@nis_project_id
)
),
'[^a-zA-Z0-9]',
'_'
)
END
The goal is to generate an ID based on the values of other fields when a new feature is created, but not to have the ID change if the feature is updated.
When I set the 'Apply default value on update' option, the ID is generated as expected, but also updates every time an attribute of the feature changes, which is not what I want.
When I do not set the 'Apply default value on update' option, the ID is not generated correctly when I input a new feature. It seems to ignore the values of other fields that are supposed to be used in generating the ID.
Could anyone guide me on how to set the default value based on the expression above, such that it considers the values of other fields at the time of feature creation and does not update automatically with each feature update?
Edit: Even with unchecked "edidable" it's still updating:
New Edit: I want the AID to be updated while the user is typing:
Here is a siplyfied test-project: Test-Project