I am trying to automatically update the content of several fields, when the first one is completed. If the value in the first field is not found, then nothing. But if the value is found, then the field 2, 3, 4, etc. are updated with their respective content.

Ex: If The first feature is

  • Field 1: "Test1"
  • Field 2: "CODE1"
  • Field 3: "CODE2"

Then, when I add another feature, if the content of the Field 1 is "Test1", the Field 2 will be completed with "CODE1" and the field 3 with "CODE2"

I have checked this page : Filling fields instantly and automatically when creating new entity in QGIS The solution use python, and I'm not sure that this is my solution. Other pages are mostly dedicated to ArcGIS.

I have tried several expressions in the Default value on update (FIELD1 = the entry, used to search correspondences, FIELD2 is one of the fields I want to update)

with_variable('V', get_feature('LAYER', 'FIELD1', "FIELD1"),
    WHEN @V IS NOT NULL AND @V <> ''
    THEN attribute(@V, 'FIELD2')


WHEN attribute(get_feature('LAYER', 'FIELD1', "FIELD1"), 'FIELD2') IS NOT NULL
THEN attribute(get_feature('LAYER', 'FIELD1', "FIELD1"), 'FIELD2')


attribute(get_feature('LAYER', 'FIELD1', "FIELD1"), 'FIELD2')

I add a first feature and complete attributes First entry

Second, I would like to get the same attributes, when I use the same content in the first field. Result

Right now, any of these expressions will automatically remove the content of the fields instead of completing it. When I add a feature whose FIELD1 has no equivalent in the layer, then when I complete FIELD2 and FIELD3, the FIELD2 will be emptied, and vice versa.

  • Can you show an example of the output you're wanting even if its drawing/typing it manually. Struggling to get a grasp of what you're expecting the output to be.
    – ScoGer
    Commented Aug 17, 2023 at 22:10
  • I edited my first post with screenshots. I hope it can help show what I'm searching to do.
    – Giene
    Commented Aug 18, 2023 at 1:41

2 Answers 2


I resolved my issue by changing the expression :

with_variable('existing_feature', get_feature('LAYER', 'FIELD1', "FIELD1"),
        WHEN @existing_feature IS NOT NULL
        THEN attribute(@existing_feature, 'FIELD2')
        ELSE "FIELD2"

This way, when I write an existing value in "FIELD1", the (first) corresponding value will be searched to auto-complete FIELD2. I added a case if FIELD1 is NULL, so I can still change the value if I have to.

I put this expression in the default value of the fields I want to auto-complete.

There is no need to pre-configure another layer or relations.


Addressing this problem could be effectively accomplished through the implementation of a Lookup table. The proposed methodology involves the establishment of a dual-layer structure. The first layer is exclusively designated for the retention of text inputs and pre-configured settings for automated code outputs. In contrast, the second layer serves as the repository for the authentic data. To streamline the process, we intend to pre-fill the Lookup table with anticipated inputs and corresponding outputs. By creating a linkage between the two tables and applying specific expressions to each field, we can enhance the overall functionality. This approach will be further augmented by incorporating user-friendly value mapping for added convenience.

Step 1; Create the Lookup table layer and populate it with the input and output codes

Lookup table

Step 2; Create the layer you will manually input values into to receive the automated code outputs

Main Layer

Step 3; Create a join within your Main Layer,"join" layer

Creating Join

Step 4; Goto the attribute form in the Main Layer and add a default value and tick "Apply default value on update"

In my example I'm using;

  • "attribute(get_feature('Join', 'field1', "Result"), 'field2')" for Code1
  • "attribute(get_feature('Join', 'field1', "Result"), 'field3')" for Code2
  • "attribute(get_feature('Join', 'field1', "Result"), 'field4')" for Code3

Image of Step 4

Image of expression form

Step 5; Create a value map to stream line data entry within the Main layer

Adding Value Map

Step 6; Create a new entry; examples

New entry1

Value map

New entry2

New entry3

New entry4

New entry5

Final Output

Final Output

  • If I understand well, the solution you proposed requires to save in another table the association between "Result" and "Code1", "Code2", "Code3", etc. In my situation, I don't know which code will be associated to the "Result". For "Test1", it might be "A1", A2, "A3", or anything else.
    – Giene
    Commented Aug 18, 2023 at 11:00

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.