3

I have two tables: "enforcements_live" and "enforcement". I'm trying to pass the value of an attribute for the selected feature in the enforcements_live layer (value from field fref) through to the enforcement layer (field enfref) but only when a feature is selected in enforcements_live.

e.g. I want the value of the fref field for the selected feature in table enforcements_live to be passed through to the field enfref of table enforcement at the time I create my new feature in table enforcement.

I've attempted this through the is_selected and get_feature functions but I'm only getting a null value being returned. Is this something that's possible to do? From searching, I haven't been able to find any working examples.

5
  • Given that you have tried get_feature, is a workaround accepted based on the value of another defining field, and not the selection of the enforcements_live table?
    – kowalski
    Commented Nov 29, 2022 at 10:33
  • Unfortunately, I need the value of 'fref' for the selected feature within enforcement_live to be passed through to enfref in the enforcement table. It may be my poor implementation of the functions as I'm quite new to this. I'm trying to use this expression for a default value in the attribute form.
    – Rerun0498
    Commented Nov 30, 2022 at 15:35
  • What I meant was, instead of passing the value by selection, what if you passed it based on the value of another field? To add a new field 'define' on enforcement_live and based on the value of that field to pass the value of field 'fref'. If that's acceptable, I can post an answer based on that.
    – kowalski
    Commented Dec 1, 2022 at 16:37
  • Please, post the expression that you have tried.
    – Mayo
    Commented Dec 3, 2022 at 13:34
  • @kowalski I see what you mean now, unfortunately passing the value by selection is the only viable method I can think of. The purpose behind this which I haven't already mentioned is to build a workspace for a specific user group, I'm trying to remove as much manual work for them as possible and having the ability to select a feature on one layer and pass that features attributes when creating a new feature on a different layer would be very useful, however, if I can't make it work then manually typing a value will have to do.
    – Rerun0498
    Commented Dec 5, 2022 at 9:41

1 Answer 1

4

If I understand, you need an expression that returns the value of the fref field of the selected feature of the enforcements_live table. You will need to aggregate filtering by the function is_selected. Use this expression.

aggregate(
    layer:='enforcements_live', -- set here your layer name/id
    aggregate:='array_agg',
    expression:="fref", -- set the field
    filter:=is_selected(
        'enforcements_live',
        $currentfeature
    )
)[0]

Note: if there are more than one features selected it will take randomly the value of just one.

0

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