I am looking to autogenerate consecutive numbers per group by an attribute form default expression whilst completing a survey using QField for QGIS.
Requirements:
- A job number will only be created when a separate column, "SpanClear" = No.
- I also require the job numbers to reset to 1 for each unique group in the column named "CircuitID".
- As this is a survey to be completed in QField, the attributes start off empty/null and will be populated on a mobile device
- Each time a job is identified (by "SpanClear" = 'No'), the jobs should be consecutively numbered, 1, 2, 3... etc.
- I require an expression to add in the default value of the attributes form (if there is a better way, please let me know)
I have searched through many previous questions and although there are workarounds using plugins, virtual layers and tools in QGIS, I require an expression so it will work in QField.
I want to automate the numbering to reduce chances of errors during surveying.
The expression I have created so far is:
CASE
WHEN "SpanClear" = 'No'
AND
"JobNo" is NULL
THEN $id=array_first(array_agg($id, "CircuitID"))
WHEN "JobNo" is not NULL
THEN array_agg((maximum("JobNo")+1),"CircuitID")
ELSE
NULL
END
The above expression names the first job per group "1", but any following jobs are set to "0".
Is what I am asking for even possible through an expression? I'm not a developer so I may have missed something obvious.
How it will look in QField
How the current expression is autopopulating
How the expression looks in Attributes Form