# Survey123 URL Scheme to Collector - Arcade Function Issue

1069
4
10-20-2020 07:42 AM
New Contributor III

Hello Everyone,

We use URL schemes frequently to pass values through from Collector to Survey123. We were just creating a basic URL scheme and adding to the collector popup as a link like the 1st example below:

arcgis-survey123://?itemID=<surveyid>&field:name1={name1}&field:name2={name2}&field:name_new={name_new}&field:rel_globalID={GlobalID}&center={XY}

The above works well, but we ran into a problem when passing the center value over to the survey when we are creating XYs on the fly with an Arcade expression. We switched the above flow to an Arcade based URL scheme in the 2nd example below and this works really well for our centering on the fly:

function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
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=<surveyid>";
var url = url_scheme + "&field:=name1={name1}" + "&field:name2={name2}" + "&field:name_new={name_new}"  + "&field:rel_globalID={GlobalID}" + "&callback=https://collector.arcgis.app";
var url = url + "&center=" + lat + "," + lon;
Console(url);
return url;
}

var latlon = MetersToLatLon(Geometry(\$feature).X, Geometry(\$feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

Today, I added a new field in our hosted feature service (name_new) that passes the values to the survey form. I would like to pass that value using the Arcade expression above, but it will not apply the value to the form. It only shows the field with curly brackets {name_new} in the form.

To add to the confusion, the basic URL scheme from my 1st example does work and brings over the correct value instead of the field name {name_new}. I would like to continue using the arcade formula in the 2nd example because it can be applied quickly to our numerous projects. Has anyone run into this before?

Thanks!

Tags (3)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Hi Stantosa ,

What happens if you parse the actual field values to be included in the url inside the Arcade expression, like this:

``````function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
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 = "arcgis-survey123://?itemID=<surveyid>";
url += "&field:name1=" + \$feature["name1"] + "&field:name2=" + \$feature["name2"];
url += "&field:name_new=" + \$feature["name_new"] + "&field:rel_globalID=";
url += \$feature["GlobalID"] + "&callback=https://collector.arcgis.app";
url += "&center=" + lat + "," + lon;
Console(url);
return url;
}

var latlon = MetersToLatLon(Geometry(\$feature).X, Geometry(\$feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
4 Replies
MVP Notable Contributor

What I do is have the Arcade calc the value I want to send, then use that like a field in a static URL link.  Works great.  I though returning a URL from Arcade would be an issue and it looks likes it is.

arcgis-survey123://?itemID=269b8fefe93b4aa782cdfd873ed1950f&field:PointID={PointID}&field:DesignLat={expression/expr1}&field:DesignLong={expression/expr0}

Hope that helps.

var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lon = (Geometry(\$feature).x / originShift) * 180.0;
var lat = (Geometry(\$feature).y / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);

return lat;

(or return long or can return both as a sting)

New Contributor III

Thanks for the reply Doug, this was a good solution as well.

Esri Esteemed Contributor

Hi Stantosa ,

What happens if you parse the actual field values to be included in the url inside the Arcade expression, like this:

``````function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
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 = "arcgis-survey123://?itemID=<surveyid>";
url += "&field:name1=" + \$feature["name1"] + "&field:name2=" + \$feature["name2"];
url += "&field:name_new=" + \$feature["name_new"] + "&field:rel_globalID=";
url += \$feature["GlobalID"] + "&callback=https://collector.arcgis.app";
url += "&center=" + lat + "," + lon;
Console(url);
return url;
}

var latlon = MetersToLatLon(Geometry(\$feature).X, Geometry(\$feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
New Contributor III

This worked really well! Thank you Xander for the response and appreciate it!