English

How To: Launch and populate a Survey123 survey from Collector for ArcGIS using XY coordinates and attributes from an existing feature service

Summary

As you may know from the What’s New in Collector for ArcGIS 18.1.0, Arcade expressions are now supported. Integration between Collector for ArcGIS and Survey123 has always been in high demand and we now have the opportunity to build Survey123’s custom URL scheme using an Arcade expression.
 
“Why does that matter?”

If you have a Collector Web map based on an existing service and wish to populate a Survey123 survey that is using a different feature service, use the custom URL scheme and custom attribute pop-up to do this, for example:

arcgis-survey123://?itemID=<itemid>&field:AssetID={otherfeatid}

populates the survey with the field “AssetID” with “otherfeatid” from the existing service. However, Survey213 will default to your current location and not the point you may have used in the Collector map when you launch Survey123.

 

Procedure

To configure the Web Map pop-up to use an attribute expression refer to: Configure pop-ups
 
Paste the following, fixing the <itemID> with the item ID of your survey.

function MetersToLatLon(x, y) {
    // Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
    // Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    var originShift = 2.0 * PI * 6378137.0 / 2.0;
 
    var lon = (x / originShift) * 180.0;
    var lat = (y / originShift) * 180.0;
 
    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
    return [lat, lon];
}
function CreateURLSurvey(lat, lon) {
    var url_scheme = "arcgis-survey123://?itemID=<itemid>";
    var url = url_scheme + "?";
        url = url + "&field:AssetID={otherfeatid}";// Repeat this line as many times as required based on how many fields you want populated. For this example AssetID will be populated from otherfeatid
    url = url + "&center=" + lat + "," + lon;// This is the line that defines the location
    Console(url);
    return url;
}
 
var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;
var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

Related Information