Select to view content in your preferred language

Arcade pop up with FeatureSetByRelationshipName not working offline

1346
4
07-11-2022 09:53 AM
JeffreyFitzgibbons
Emerging Contributor

Hi, I am having an issue with an Arcade expression in a pop while using field maps, specifically in offline mode. I have a feature class (monitoring well) and a linked standalone table (gauging_data). For the popup, I have an arcade expression pulling the most recent data and then I pass that to a survey123 link for further data collection. This all works great online (as shown) but when I pull the map offline I get the following error: 

Expression Name: expr1
Expression Title: Date
Error Domain: com.esri.arcgis.runtime.error
Error Code: 15
Error Description: Invalid call., Unable to evaluate arcade expression. Evaluation_error_code::field_not_found Line :19

My arcade expression is as follows:

var relatedrecords = FeatureSetByRelationshipName($feature,"Gauging_Data", ['Well_ID','Depth_to_Water_ft_BTOC', 'Total_Well_Depth_ft_BTOC'], false);

var cnt = Count(relatedrecords);

var relatedinfo = "Date_and_Time";

if (cnt > 0) {
    
    var sortedrecords = OrderBy(relatedrecords, "Date_and_Time DES");

        var latestinfo = First(sortedrecords);
    
    
    relatedinfo = Text(ToLocal(latestinfo["Date_and_Time"]), "M/D/Y");
    
} else {
    
    relatedinfo = "None available";        
}


return relatedinfo

I am thinking it might have something to do with GUID/Global ID case sensitivities (https://community.esri.com/t5/arcgis-field-maps-questions/featureset-not-working-offline-in-field-ma...), but since I am using FeatureSetbyRelationshipName, I am not sure how to fix. In my case 'Well ID' is my GUID field I am using to link to the feature class. Thanks. 

 

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

If I recall correctly, that FeatureSetByRelationshipName function queries the feature service URL. It does not require the layer to be present in the map, which in an online environment, is one of its benefits.

If you need to work offline, your best bet is to use FeatureSetByName or ID so that you can direct the map to look at already-loaded features in other layers.

- Josh Carlson
Kendall County GIS
JeffreyFitzgibbons
Emerging Contributor

Thanks for the help. I figured that may be an issue. I changed the expression to the following: 

 

// first read out the GlobalID of the Feature
var code = $feature["GlobalID"];

// create a sql expression to query on GlobalID
var sql = "Well_ID = '{" + Upper(code) + "}'";
Console(sql);

// access the table
var tbl = FeatureSetByName($datastore,"Gauging_Data");

// filter the table using the sql expression
var relatedrecords = Filter(tbl, sql);

// get a count of the related records
var cnt = Count(relatedrecords);

// initialize a variable that will contain the information to return
var relatedinfo = "Depth_to_Water_ft_BTOC";

// only proceed if you have related records
if (cnt > 0) {
    // sort those records by date descending 
    // change "insp_date" by the date field in your related data
    var sortedrecords = OrderBy(relatedrecords, "Date_and_Time DES");

    // get the first record of the sorted related info
    var latestinfo = First(sortedrecords);
    
    // get the last date and other information if relevant
    relatedinfo = Text(latestinfo["Depth_to_Water_ft_BTOC"]);
    
} else {
    // in case you don't have related info
    relatedinfo = "None available";        
}

// return the result
return relatedinfo

 

 

However, now the issue I am having is the expression isn't working at all online via the field maps mobile app (online or offline), but it works fine in Map Viewer. Is there something I am not understanding about how this expression is supposed to execute? 

Also, the error I am getting in Field Maps is: 

Expression Name: expr0
Expression Title: DTW:
Error Domain: com.esri.arcgis.runtime.services.error
Error Code: 400
Error Description: , Unable to perform query. Please check your parameters.

0 Kudos
jcarlson
MVP Esteemed Contributor

Strange. Does it work in Field Maps if your map is online, or is it not working at all?

Ordinarily, I'd suggest adding Console messages to the expression, but I don't know if there's a way to view console messages in Field Maps...

- Josh Carlson
Kendall County GIS
0 Kudos
DougBrowning
MVP Esteemed Contributor

Yes Relationship by name has some bugs in it - one is a . in the name.  Using By Name works better.  Search the forum this has been posted a number of times.

0 Kudos