Select to view content in your preferred language

Survey123: 'File not found: zone_lookup.js' Error – Auto-Populating Reach Number by Location

159
1
07-21-2025 12:03 PM
IsabelleCroteau
New Contributor

Hi all,

I'm building a Survey123 form in Connect to collect habitat data. I want to automatically populate the "Reach Number" field based on the user's GPS location, using a polygon layer I’ve already created (each polygon represents a habitat reach zone).

Right now, I’m attempting to do this with a JavaScript file (zone_lookup.js) and the pulldata("@javascript") function. However, I’m getting the following error in the field app:

File not found: zone_lookup.js

Here’s what I’ve done so far:

  • I referenced the JS file in the XLSForm with pulldata("@javascript", "zone_lookup.js", "getZone", ${gps_location})

  • Here is JS 
function findZone(lat, lon, zones) {
    for (var i = 0; i < zones.features.length; i++) {
        var zone = zones.features[i];
        var coordinates = zone.geometry.coordinates[0];
        if (pointInPolygon([lon, lat], coordinates)) {
            return zone.properties.reach_ID; // Adjust to your attribute
        }
    }
    return "Unknown";
}

// Basic point-in-polygon function
function pointInPolygon(point, vs) {
    var x = point[0], y = point[1];
    var inside = false;
    for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
        var xi = vs[i][0], yi = vs[i][1];
        var xj = vs[j][0], yj = vs[j][1];
        var intersect = ((yi > y) != (yj > y)) &&
                        (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
        if (intersect) inside = !inside;
    }
    return inside;
}
​

Before I dive deeper, I’m wondering:

  1. What’s the proper way to structure the zone_lookup.js file to query a polygon feature based on location?

  2. Is there a better approach to this (like using pulldata("@layer")) if I already have a hosted feature layer with the polygon zones?

  3. Will either of these methods work offline in the field app?

Thanks for any help — and I’m happy to share my XLSForm if needed.

0 Kudos
1 Reply
Neal_t_k
Frequent Contributor

the pulldata (@layer)  point in polygon usage might fit better however it is only going to work online.

https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-pulldata-quot-laye...

There doesn't  currently appear to be a way to pull data from an offline source.  This was an interesting take: 

https://community.esri.com/t5/arcgis-survey123-questions/any-similar-function-to-pulldata-to-work-wi...

Another thought would be, could you handle the zone field in post processing? Like write a python script to programmatically fill the zone field after submission based on the point coordinates collected in the survey. 

 

0 Kudos