Field calculation FeatureSet function failing within iOS mobile platform

318
2
03-31-2022 07:53 AM
ajevans429
New Contributor III

Is anyone else having any trouble with this? Creating an expression that uses a featureset (by ID or by name) fails to run properly on iOS devices. It does however, run properly on Android. Here's the beginning of a code that I was working on: 

var  activityid = $feature["related_global_id"]; //pull activity id from current related record attribute

var activitysql = "GlobalID = '" + activityid + "'";//create sql expression to filter activity records feature set

var activitytbl = FeatureSetByName($datastore,"Tree Activity"); //access tree activity table

var activityrecords = Filter(activitytbl, activitysql);//isolate related activity record(s)

var activitycnt = Count(activityrecords);//count the number of records returned after filtering

var activity = First(activityrecords);

var treeid = "";

if (activitycnt == 0) {
  return null;
} else {
    treeid = activity.related_global_id;
}

return treeid

 'treeid' returns properly on android but not our ipad.

0 Kudos
2 Replies
DougBrowning
MVP Esteemed Contributor

My guess would be a memory issue.  It does work on iOS I use it a lot.  Other one to watch out for is if you are offline the lookup records need to be offline also.

You can reduce memory and improve speed with some code changes.  I would also use map not datastore.

FeatureSet lets you ask for just 1 field ['CollectCoreSubset1'] and not send back geometry, the false part, since you do not need it.

FeatureSetByName($map,"Points", ['CollectCoreSubset1'], false)

I think you have some logic issues here also with the double return - this could be causing it to return null and cause issues.  I shorted a bit and return "" instead.  I use the dot notion on fields.  Note you can pick any field I just picked gloablid in the related table.  Also the last step not sure that related field is in the related table or just the parent.  Either way you already know it so no need to read the table value.

 

 

 

 

var activitysql = "GlobalID = '" + $feature.related_global_id" + "'";//create sql expression to filter activity records feature set

var activitytbl = FeatureSetByName($map,"Tree Activity", ['GlobalID'], false); //access tree activity table

var activityrecords = Filter(activitytbl, activitysql);//isolate related activity record(s)


if (Count(activityrecords) == 0) {
  return ""
} 
else {
    return $feature.related_global_id;
}

 

 

 

 

Hope that works

0 Kudos
ajevans429
New Contributor III

Wow, thanks for the tips! Although the way you rewrote it wasn't exactly what I was trying to accomplish, you helped me narrow down the issue. It seems like the iOS app won't process the 'FeatureSet($datasore,...' scenario, but 'FeatureSet($map,...' works just fine. It's interesting to note that the former (datastore) works just fine when used within the Android app. We are not working offline at this time, btw.

Here's my full code below. Just to add: I'm trying to access the attributes of a parent feature that's twice removed (tree site -> tree activity -> risk assessment form). The 'risk assessment form' is the one I am trying to apply this expression to. Feel free to reply with any other suggestions for cleanup!

var activitysql = "GlobalID = '" + $feature.related_global_id + "'";//create sql expression to filter activity records feature set

var activitytbl = FeatureSetById($map, /* Tree Activity */ "Forestry_Tree_Sites_4869", ['GlobalID','related_global_id'], false); //access tree activity table

var activityrecords = Filter(activitytbl, activitysql);//isolate related activity records

var activity = First(activityrecords); //isolate the individual record

var treegid = ""; //initiate a variable to hold result

if (Count(activityrecords) == 0) {
  return ""
} 
else {
    treegid = activity.related_global_id;
}

var treesitesql = "GlobalID = '" + treegid + "'";//create sql expression to filter 'tree site' records

var treesitetbl = FeatureSetById($map, /* Forestry Tree Sites */ "Forestry_Tree_Sites_2068", ['GlobalID','latin_genus','latin_specific_epithet','dbh_class','height_class','tree_condition'], false);

var treesitefeatures = Filter(treesitetbl, treesitesql);//isolate related 'tree site' features

var treesite = First(treesitefeatures); //isolate the individual feature

if (Count(treesitefeatures) == 0) {
    return ""
}
else {
    return Proper(treesite.latin_genus) + " " + treesite.latin_specific_epithet //retun latin name of tree
}