In the previous question, this is the link:

QGIS automatic fill of the attribute table by expression

I got help from a colleague and solved the problem of automatic fill of attributes and the code


does the job perfectly if I use it in the field calculator. When I entered the code in the form attributes and set it to be the default value -> Preview shows '1' but fills the attribute table with the value 'NULL'. And to make it even more interesting, if I record a line with Mergin Maps in that project and synchronize the data, the table is correctly filled with the value it should be. enter image description here

enter image description here

  • 1
    When I use it for definition of Default value, it works perfectly. What fieldtype is the field Red? What is the data source (Geopacke, Shapefile, other)? I also see you have a Form layout, maybe that does interfere? Could you share your project with (dummy) data?
    – Babel
    Commented May 2, 2023 at 13:19
  • @babel I'm sorry I didn't share the data earlier, a bit of field work got in the way. Now here I am, sharing some data (this is a really small part) so any advice is appreciated. If you have time to look at the project as a whole (go through the other layers), share your advice on how to "make it easier" for the project to work more easily on a mobile device. Maybe change the logic in some code and simplify it. Thank you! Here is link to the project. drive.google.com/drive/folders/…
    – sttipa
    Commented May 3, 2023 at 7:43
  • 1
    Add this as an answer and accept it by hitting the checkmark next to it. So it is easier to find for others.
    – Babel
    Commented Jun 14, 2023 at 9:11

1 Answer 1


I would like to maybe help someone else with a similar or the same problem. In the attribute form / drag and drop designer / Form layout is set -> I found that if the specified attribute is not set in the Form layout, the default value on update does not work, and the formula itself in the field calculator is correct and when it is only started constantly, it does its default job . I solved the problem by adding the field to the Form layout and making it hidden. lp

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.