Collector (Aurora) Custom Expressions in Custom URL Scheme Error

7448
11
04-11-2019 07:44 AM
by Anonymous User
Not applicable

I am writing a campsite collection form that uses Collector and Survey 123. I set this up using Arcmap's custom URL scheme. The user can select a site in collector and two links are included in the pop-up. One says Resurvey Campsite the other says Survey New Site. The resurvey link has a rather lengthy URL that attempts to pre-fill many of the fields of survey123. This worked other than the attributes that I had custom expressions to set correctly. The final bit the resurvey link sends the coordinates of the campsite using another custom expression.

Unfortunately, the custom expressions would work on my desktop, but when I opened collector on the iPad issued to me, they would not. I posted on this issue and was informed that Collector Aurora would support custom expressions in the URL link. I signed up for the beta and had fair success with the iPad. Some custom expressions still didn't send but coordinates did, and they were the most important one to work.

Now that Collector (Aurora) is officially out, I went out and field tested the two apps to discover that custom expressions are once again not working on my iPad or Samsung Galaxy phone. I am curious is this is a known issue and can be fixed or not, as it is rather pivotal that I can at least send the coordinates of the point to Survey 123. Below is my custom URL scheme for the resurvey link and the steps I went through to test if the custom URL was truly the issue

Resurvey Campsite Link - (&center={expression/expr2} is the non-functioning part)

arcgis-survey123://?itemID=1284e4815d4c4995b5809f1a51a83f9f&field:District={expression/expr1}&field:Wilderness_CRD={expression/expr3}&field:Wilderness_BRRD={expression/expr4}&field:Wilderness_CRRD={expression/expr5}&field:New_Site=no&field:Date_Orig_Collection={calOrigYear}&field:Campsite_ID_Number={expression/expr0}&field:Dist_Along_Trail={Dist_Along_Trail}&field:Ground_Dist={Ground_Dist}&field:Tree_Damage={Tree_Damage}&field:Disturbed_Area={Disturbed_Area}&field:Overall_Imp={Overall_Imp}&field:Between_Trail_Stream={Between_Trail_Stream}&field:Water_Source={expression/expr7}&field:Water_Dist_FT={Water_Dist}&field:Social_Trails={Social_Trails}&field:Main_Trail_Designated={Main_Trail_Designated}&field:Trail_Dist_FT={Trail_Dist}&field:Impact_Area={expression/expr6}&field:Litter_Trash={Litter_Trash}&field:Pot_Site_Expan={Pot_Site_Expan}&field:NNIS_Presence={NNIS_Presence}&field:Site_Condi={Site_Condi}&field:Rec_Site_S={expression/expr8}&field:Admin_Structures={Admin_Structures}&center={expression/expr2}

Resurvey Campsite Link Output on Desktop

arcgis-survey123://?itemID=1284e4815d4c4995b5809f1a51a83f9f&field:District=CRRD&field:Wilderness_CRD=&field:Wilderness_BRRD=&field:Wilderness_CRRD=MT&field:New_Site=no&field:Date_Orig_Collection=2007&field:Campsite_ID_Number=1&field:Dist_Along_Trail=&field:Ground_Dist=1&field:Tree_Damage=1&field:Disturbed_Area=1&field:Overall_Imp=3&field:Between_Trail_Stream=&field:Water_Source=1&field:Water_Dist_FT=45&field:Social_Trails=%20&field:Main_Trail_Designated=&field:Trail_Dist_FT=-100&field:Impact_Area=3&field:Litter_Trash=%20&field:Pot_Site_Expan=Medium&field:NNIS_Presence=Unknown&field:Site_Condi=Fair&field:Rec_Site_S=&field:Admin_Structures=N%2FA&center=34.745047%2C%20-83.844254

Expression/expr2 - Code to calculate geometry

function metersToLatLon(mx, my) {

   var originShift = 2.0 * PI * 6378137.0 / 2.0;

   var lon = (mx / originShift) * 180.0;

   var lat = (my / originShift) * 180.0;

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

return [lat, lon];

}

var poly = Geometry($feature);

var result = '';

if (!IsEmpty(poly)) {

   var latlon = metersToLatLon(poly.x, poly.y);

   result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);

}

return result;

Process for Testing Error

  • After noticing the error in the field, I retested each device in the office

     Desktop (Success)                          iPad (Error) - Newest Collector App             Android (Error) - Beta App

  • I then created a third link that only included the code to send the coordinates and tested it on each device

    Link - arcgis-survey123://?itemID=1284e4815d4c4995b5809f1a51a83f9f&center={expression/expr2}

    Desktop (Success)                       iPad (Error) - Newest Collector App             Android (Error) - Beta App

  • Finally, I created one more link that sent a fixed coordinates instead of using the custom expression

Link - arcgis-survey123://?itemID=1284e4815d4c4995b5809f1a51a83f9f&center=34.734837%2C%20-83.916739

     Desktop (Success)                       iPad (Success) - Newest Collector App             Android (Success) - Beta App

Thank you for anyone who has made it this far, I would really appreciate any help on resolving this bug as I'm super excited about using Collector and Survey 123. Good work!

11 Replies
MarkBockenhauer
Esri Regular Contributor

I tried the following with a map in Collector (IOS) and it passed the coordinate via an expression to Survey123

var polyx = text(centroid($feature).x);
var polyy = text(centroid($feature).y);

function metersToLatLon(mx, my) {

   var originShift = 2.0 * PI * 6378137.0 / 2.0;

   var lon = (mx / originShift) * 180.0;

   var lat = (my / originShift) * 180.0;

   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];

}

var latlon = "";
var result = "";
var latlon = metersToLatLon(polyx, polyy);

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);


return result;

For the link

arcgis-survey123:///?itemID=7e7dd26a96db4338bcdae969d9d05398&center={expression/expr0}

by Anonymous User
Not applicable

Thank you for the response. I tried your code in place of mine and had the exact same result as mine. It works on my desktop (windows 10), but not on my iPad or android phone. I used the link you provided (and was thankfully able to open your water leak report survey) and also had the exact same problem. The coordinates were passed just fine on my desktop, but did not work on my iPad or Android.

When you say it worked for you in IOS, where you using a mobile device or a desktop?

0 Kudos
MarkBockenhauer
Esri Regular Contributor

I opened this webmap https://www.arcgis.com/home/item.html?id=0062ba474d7b467dad3e6f75ffd6a7a8

In Collector and tapped a polygon for Popup.

Could you try this map?

0 Kudos
by Anonymous User
Not applicable

Further update, I realized when I say it is working in desktop that I was opening that from the arcmap online map that I've used to design the app.

I opened the actual collector app on my windows computer and it failed to send the coordinates to survey123 as well. This isn't too surprising though as this is still the older version of collector and not aurora (I'm fairly certain).

0 Kudos
MarkBockenhauer
Esri Regular Contributor

Definitely need to use New Collector for this.  Were you able to try the map I referenced in Collector on IOS?

0 Kudos
by Anonymous User
Not applicable

I was able to try your map, both in Arcmap Online and on my iPad. It worked perfectly both in displaying the coordinates and the link to survey123. I then mimicked your design and added the geometry expression to my pop-up. This finally found the actual issue! Below is the screenshot of Collector on the iPad. The section that says Coordinates:  is where I have my custom expression which as you can see is outputting 0.000312, -0.000754. This is why my survey123 is opening at 0, 0.

The only difference between our maps that I could immediately think of was that mine is prepared for offline use. So I made a copy of my map and didn't have it set up for offline mode. I then opened it on the iPad. It works perfectly! As you can see below, the coordinates are reported perfectly (and the Resurvey Campsite link sent the correct coordinates to Survey123. This clearly shows that the map being in offline mode is somehow affecting the custom expression, but I'm not sure yet how. When I'm back at work tomorrow I plan to test the other custom expressions to see if they are changing at all between online and offline mode. Thank you so much Mark! I have been so frustrated by this and your help has gotten me to the actual problem finally!

0 Kudos
WarrenCarver1
New Contributor II

So I have got it working now!

Long story short in online mode the code

 text(centroid($feature).x);

outputs

-9331888.963170711

This then needs to be converted to longitude to be sent to Survey123.

In offline mode though, the exact same code

 text(centroid($feature).x);

outputs

-83.829785

This is already in longitude and does not need to be converted to be sent to Survey123. Since the conversion was still being run though, Survey123 was being sent something that is approximately 0. I have no idea why this change happens, but I made a small edit to Mark's geometry code that checks if the absolute value of

var polyx = text(centroid($feature).x);

is greater than 10,000. If it is, then it runs the conversion, if it isn't then it doesn't. This means the custom expression is now working in the Arcmap Online map and on the Collector Aurora (I have tested it on my iPad). Such a simple fix that was ridiculously frustrating to find! Here is the full code for anyone else who runs into weird issue.

var polyx = text(centroid($feature).x);
var polyy = text(centroid($feature).y);

function metersToLatLon(mx, my) {
   var originShift = 2.0 * PI * 6378137.0 / 2.0;
   var lon = (mx / originShift) * 180.0;
   var lat = (my / originShift) * 180.0;


   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);
   return [lat, lon];
}

var latlon = "";
var result = "";
var latlon = [];

if (Abs(polyx) > 10000) {
   latlon = metersToLatLon(polyx, polyy);
}
else {
   latlon = [Number(polyy), Number(polyx)]
}

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);


return result;

MarkBockenhauer
Esri Regular Contributor

Warren,

 

How are you taking the map offline?

I used a Map Area (pre-planned) and did not reproduce your experience (it worked as expected), did you use Collector to take the map offline (Adhoc)?

I will be sharing this experience with the team.  There are plans on the Arcade side to allow for specifying the coordinate system of the coordinates, but until that work is completed and delivered, this is really good to know.


Thanks,
Mark

0 Kudos
WarrenCarver1
New Contributor II

Mark,

As the collection is being done in Forest Service Wilderness areas, offline mode was a necessity. Under the map settings I have offline mode enabled and have defined 12 offline areas. Below is a screenshot of my specific maps settings. I want to make sure I'm answering your question correctly as this is the only way I thought you could use a map offline.

Another difference I can think of is that the data I'm accessing (the point feature layer) is the output feature layer for my Survey. Not sure if that makes sense, so my survey R8 Wilderness Campsite Survey outputs data to the feature layer (hosted) R8 Wilderness Campsite Survey. This layer is in the Online Map titled AT/Wilderness Campsite Inventory that is set to Offline Mode Enabled for Collector. I have then created a view layer of R8 Wilderness Campsite Survey that filters the data so that only select sites are displayed. This view layer of the survey layer is the specific feature layer (sorry for saying layer so much there), that I am using the custom expression with and that this effect occurred.

Finally, I formatted all of our old campsite data to match the format of the R8 Wilderness Campsite Survey feature layer and uploaded it into the layer using Update Data > Append Data to Layer. These are all the things I've done that I can think of that might impact my map behaving differently to what is normally expected.

If any of that blathering doesn't make sense or further info would be helpful, please let me know! Again, thank you for the help!

0 Kudos