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.
When I create the feature, I get the '11111' value, which tells me my condition is caught, but no element of the coalesce work.
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
feature
function do you mean? To test any answers to you r question, one first has to start to rebuild the exactly same project/data as you have it. From the description it is a bit difficult to understand and, anyway, cumbersome to create an exactly matching project. So to boost your chances to get an answer, I would advice to post a link to a sample project with dummy data so that one can see what you have.feature
function in QGIS expressions. You meanget_feature()
function? But this is not new.... Anyway - without a sample project or some screenshots, to me the questions remains unclear, even with the additions you made. Don't know why you don't want to post additional information and let people here working to re-create the setting you already have instead of helping them to help you solve your problem...fid
, you set a default value ofrand(1,10000)
- you should not do that, Geopackage handles unique fid-values automatically and interfering just complicates things and adds to the confusion about what you intend to achieve.