I would like to use @cloud_username to filter the layer that is set as geofencing layer. This way I can create a dynamic geofence. Consider a polygon layer with suburbs. A project manager can fill an attribute ‘surveyor’ with usernames and set a filter to that layer (“surveyor = @cloud_username )This layer is set as the Geofencing layer. So user 1 is assigned to suburb a, user 2 to b etc.
Now, when a user opens the project in the QFied app the Geofence is applied based on the username.
Consider the polygon layer with suburbs. I add two new fields, surveyor and active. The field surveyor is populated by the project manager with cloud usernames: user1 for suburb a, user2 for suburb b, etc
The field active is a boolean type which has Default set as “surveyor” = @cloud_username
Then, a filter can be applied with the expression “active” = TRUE
However, this will only work when ”active” is being updated on opening the project in QField. I have not found a way for this to happen yet. I can set the field active to Apply default value on update, but I am not updating this layer as a QField user, I am only opening the project.
Is there some kind of trigger that will update the field “Active” on opening the project in QField? And then apply the filter as next step?
Hi! I unfortunately haven’t worked with filters so far, but you can set up expression-based permissions for a layer, which might give you the result you want.
If I remember correctly, the example below would make it so that a feature can only be edited if the @cloud_username matches the value in the field “user”, when put in “Disable attribute editing”, “Disable feature deletion”, and “Disable geometry editing”.
It does work when I set the ‘user’ per feature. That is however not what I am looking for, I want to set it so a user can only edit a point feature laying within a certain polygon.
I tried overlay_within(‘polygonlayer’, filter:= surveyor != @cloud_username)
Here I run into the same issue that a filter expression does not work with variables.
If I use a hardcoded value in stead of @cloud_username it does work. This unfortunately is not the solution, because it no longer is dynamic.