QField icon indicating copy to clipboard operation
QField copied to clipboard

ERROR with expression "get_feature_by_id", different line number

Open Ipickedausername opened this issue 2 years ago • 5 comments

Hello,

I'm posting the same issue I posted on the QfieldSync Github, because the issue could be coming from QFIELD, more than QFIELD Sync.

To sum up, there is a difference with "attribute(get_feature_by_id)" I usually write it like it : "attribute(get_feature_by_id('Alias',1-1),'Alias')" ( search in Alias, the ID = 1 (-1))

But when I'm exporting on the cloud (no with cable), I have to delete "-1" to make it works. "attribute(get_feature_by_id('Alias',1),'Alias')"

The error seems coming from the id of the lines in a table which usually starts at 0, but starts at 1 when exported via QFIELD Sync "cloud".

Post on QFIELD Sync Github : https://github.com/opengisch/qfieldsync/issues/427


I'm loading a list in a field, filtered by this expression :

CASE WHEN string_to_array(attribute(get_feature_by_id('OPTIONS',0),'Compart'), '-')[0] = 0 THEN string_to_array("Compart", '-')[0] <> 0 ELSE string_to_array("Compart", '-')[0] = string_to_array(attribute(get_feature_by_id('OPTIONS',0),'Compart'), '-')[0] END

When the first number of "Compart" (in layer OPTION") = 0 then load everything except the one starting with a '0'. Else, load the results which start by the selected number.

Everything is working when I'm exporting the project with cable.

Here two pictures of the working list.

working_2 working_1

But, when I'm exporting the project on cloud, this is not working anymore.

Not_working-1

The list is loaded from another layer :

Compartiment

To ensure it is working, I have to change the expression like this :

CASE WHEN string_to_array(attribute(get_feature_by_id('OPTIONS',1),'Compart'), '-')[0] = 0 THEN string_to_array("Compart", '-')[0] <> 0 ELSE string_to_array("Compart", '-')[0] = string_to_array(attribute(get_feature_by_id('OPTIONS',1),'Compart'), '-')[0] END

To sum up, I'm changing the ID in get_feature_by_id from 0 to 1. In the first case, the corresponding row is 0, in the second case it is .

I can't change my project to make it work on the cloud, because I'll not be able to use it on QGIS anymore.

Do you know where is it coming from ? I guess there is en error somewhere.

Thank you !

Ipickedausername avatar May 30 '22 13:05 Ipickedausername

Well, it seems that get_feature_by_id can't be used if the project is dedicated to be uploaded on the cloud. To avoid this issue, I'm not using this expression anymore, but only get_feature. This one is working.

Ipickedausername avatar Jun 13 '22 01:06 Ipickedausername

@Ipickedausername , can we close this issue?

nirvn avatar Jun 13 '22 01:06 nirvn

I think this is an error from QField cloud. I can share a project as an example. In my case, I think I just found another way to make it works, but the error is still existing.

Ipickedausername avatar Jun 13 '22 04:06 Ipickedausername

Sharing a sample project is always is a good idea.

Note that layers marked as "Offline editing" do CANNOT have a stable feature id in projects after exporting. To be honest, stable feature ids across different QGIS seasions also are not guaranteed, unless they are 64bit integers in the original data source.

suricactus avatar Jun 13 '22 07:06 suricactus

Hi !

I attach a project. Don't pay attention to the error messages. I deleted many relations.

Here is the situation : If the project is exported via cable, the field COMPART_1 will work (as on QGIS) If the project is exported via Cloud, the field COMPART_1 is not longer working, but the field COMPART_2 is now working. Because the searched id isn't 0 anymore, but 1.

I don't know if I'm really clear.

The field COMPART is always working, because I changed the expression, I'm not using get_feature_by_id anymore.

Test_QGIS.zip

Ipickedausername avatar Jun 14 '22 11:06 Ipickedausername