I read the documentation, examples and made many attempts, but I still can't make this work.
What I want is to get a value from a parent layer while editing a child layer, when both features are being created in a embedded forms setup. So far, I can't seem to make current_parent_value() and current_value() work in an embedded forms setup.
I'm using QGIS 3.28 (tried with previous versions too) on Windows 10.
Let's say I have two nested forms: Form1 and Form2. Form2 is nested inside Form1 through a Relation. The 'fid' from Form1 and 'rel_id' from Form2 are used with the Relation to link both forms. I'm trying to get the value of 'Total' field from Form1 in Form2.
To try and understand what works and when I did this Case/When with a Coalesce.
case when "rel_id" is not null then coalesce( current_parent_value('Total'), attribute(get_feature('Form1','fid',current_value('rel_id')),current_value('Total')), attribute(get_feature('Form1','fid',"rel_id"),'Total'), 11111 ) else 00000 end
The workflow is quite simple:
- Create a feature in Form1
- From this layer, create a child feature in Form2
In the end, I want my "value" field from the child feature to get the "Total" value from the parent feature. To be clear, this is a dummy project to test the function for something more useful than this.
Then, when I update the feature afterward (change the value to trigger the "apply default value on update"), I finally get the right value, which tells me that the regular attribute(get_feature()) works.
But I really can't find a way to get the right value when creating the feature. In the end, I have the good value, but this confuses my users because they see the wrong value when they are working with the form in the field...
What am I doing wrong?
Here is a sample project to test the equation: Here