I have:

  • a parent line-layer 'MyParentLineLayer' (referenced layer) with a field "parent_uuid" (referenced field).
  • a child geometryless-layer 'MyChildLayer' (referencing layer) with a field "parent_uuid_ref" (referencing field).

I set up a relation between parent layer and child-layer as described before in project properties.

In parent-layer-properties - myRelation the checkbox "Force hide form on add feature" is checked.

I would like to get the line length of the parent-feature as a (editable) default-value in the child-features-form.

I tried:

        get_feature('MyParentLineLayer', 'parent_uuid', current_value('parent_uuid_ref'))

as default-value-expression (widget type: text-editor, field type: double) but always got a NULL-value as line-length.

What is wrong with my code/settings?

  • 2
    What is the current value function, is a custom function? I think it's just length(geometry(get_feature('MyParentLineLayer', 'parent_uuid', "parent_uuid_ref"))) remember to put double quotes in parent_uuid_ref to get the current value of the field and not a constant string.
    – Mayo
    Commented Jun 7, 2022 at 15:00

1 Answer 1


update: answer below is only relevant when adding new features in child layer. Question has since been clarified to the child form that appears when adding feature to parent layer, and using a default value that depends on unsaved parent form values. Disregard answer below.

I believe current_value() is used more for widgets that are themselves configured to use a relation reference. Your line length widget in the child layer is just a simple widget with a default value so current_value() doesn't really work (that's my understanding).

Your expression should work if you use "parent_uuid_ref" instead of current_value('parent_uuid_ref').



See below for example using above expression in default value field.

enter image description here

  • Tried this too before - but does not work in my (test-)-project. See small test-project at wetransfer.com/downloads/… .Length-value shall be available in the form already on first digitzing of line - not only after it was saved (and "apply default value on update" shall not be checked as the value shall be editable)
    – user191847
    Commented Jun 8, 2022 at 5:45
  • @user191847 That's because you have a typo - your parent layer column is parentuuid and not parent_uuid - if you change the expression to match the parent layer column name it will work.
    – she_weeds
    Commented Jun 8, 2022 at 6:09
  • Excuse me. Thanks for your advice. Fixing the typo does not help. Tried it with QGIS 3.22.2 and 3.24.2. Line length is only shown in default-value-preview but not in the child form during digitizing a line. (Modified project at wetransfer.com/downloads/… )
    – user191847
    Commented Jun 8, 2022 at 6:58
  • Ah, so you mean when you are digitising a feature in the parent layer (line layer), rather than creating a new record in your child layer (without geometry). Apologies, I didn't pick that up from your initial question. In that case, it does seem like the nested child form does not pick up UNSAVED parent attributes (or derived attributes) so I don't have an answer to your specific query, unfortunately. It may be worth raising it as an issue on github. I'll dig around a bit more to see what can be done
    – she_weeds
    Commented Jun 8, 2022 at 8:01
  • For now the best approach seems to be to add your feature in the line layer, save, then go back and edit the feature and THEN add a child feature. Alternatively, if you want to be able to edit the derived length value at the time of line feature creation, create a column for that in the line layer itself using a default value that you can edit, then reference that in your child feature (which, again, you can only create after saving the parent feature)
    – she_weeds
    Commented Jun 8, 2022 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.