Select to view content in your preferred language

Attribute Expression Blank

947
3
09-25-2018 12:42 PM
WarrenCarver1
Emerging Contributor

I am currently making Collector/Survey123 data collection and map for inventorying campsites. I am opening Survey 123 from collector by adding a link in the pop-up following arcgis's url scheme. Many of the fields have to be calculated and so I made a single attribute expression that creates the majority of the link which I named Resurvey Link {expression/expr0}. Then in the url I put

arcgis-survey123://{expression/expr0}

but when I click the link it simply appears as

arcgis-survey123://

If I open the attribute table, under Resurvey Link the two campsites I currently have in the dataset are empty.

When I test the code within the expression I get the exact result I expected, not a blank string....

Attached below is the entire expression and then the output when I test it.

function getCampsiteId() {
   return Number(Split($feature["Campsite_ID"], "-")[5]);
}

function getCampsiteOrigYear() {
   var iYearShort = Number(Split($feature["Campsite_ID"], "-")[4]);
   var sYear = '';
   if (iYearShort <= 99 && iYearShort >= 94) {
      sYear = '19' + iYearShort;
   }
   else {
      sYear = '20' + iYearShort;
   }
   return Date(Number(sYear), 0, 1);
}

function getDistrict() {
   return Decode($feature.Wilderness,
      'Blood Mountain Wilderness Area', 'BRRD',
      'Brasstown Wilderness Area', 'BRRD',
      'Cohutta Wilderness Area', 'CRD',
      'Mark Trail Wilderness Area', 'CRRD',
      'Raven Cliffs Wilderness Area', 'CRRD',
      'Rich Mountain Wilderness Area', 'BRRD',
      'Tray Mountain Wilderness Area', 'CRRD',
    '');
}

function getGeometry() {
   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;
}

function getResurveyLink() {
   var link = '?itemID=2aab379ca46543e9a812ef07a387c802';
   var geom = getGeometry();
   var fields = [
      {name: 'District', val: getDistrict()},
      {name: 'Wilderness_CRD', val: getWilderness('CRD')},
      {name: 'Wilderness_BRRD', val: getWilderness('BRRD')},
      {name: 'Wilderness_CRRD', val: getWilderness('CRRD')},
      {name: 'New_Site', val: 'no'},
      {name: 'Date_Orig_Collection', val: getCampsiteOrigYear()},
      {name: 'Campsite_ID_Number', val: getCampsiteId()},
      {name: 'Dist_Along_Trail', val: $feature["Dist_Along_Trail"]},
      {name: 'Date_Collected', val: Now()},
      {name: 'Ground_Dist', val: $feature["Ground_Dist"]},
      {name: 'Tree_Damage', val: $feature["Tree_Damage"]},
      {name: 'Disturbed_Area', val: $feature["Disturbed_Area"]},
      {name: 'Overall_Imp', val: $feature["Overall_Imp"]},
      {name: 'Between_Trail_Stream', val: $feature["Between_Trail_Stream"]},
      {name: 'Water_Source', val: $feature["Water_Source"]},
      {name: 'Water_Dist_FT', val: $feature["Water_Dist"]},
      {name: 'Social_Trails', val: $feature["Social_Trails"]},
      {name: 'Main_Trail_Designated', val: $feature["Main_Trail_Designated"]},
      {name: 'Trail_Dist_FT', val: $feature["Trail_Dist"]},
      {name: 'Impact_Area', val: $feature["Impact_Area"]},
      {name: 'Litter_Trash', val: $feature["Litter_Trash"]},
      {name: 'Pot_Site_Expan', val: $feature["Pot_Site_Expan"]},
      {name: 'NNIS_Presence', val: $feature["NNIS_Presence"]},
      {name: 'Site_Condi', val: $feature["Site_Condi"]},
      {name: 'Rec_Site_S', val: $feature["Rec_Site_S"]},
      {name: 'Admin_Structures', val: $feature["Admin_Structures"]}
   ];

   for (var i=0, j=Count(fields); i<j; i++) {
      link += '&field:' + fields.name + '=' + fields.val;
   }

   link += '&center=' + geom;

   return link;
}

function getWilderness(sWild) {
   if (sWild == 'CRD') {
      return Decode($feature.Wilderness,
         'Cohutta Wilderness Area', 'CO',
      '');
   }
   else if (sWild == 'BRRD') {
      return Decode($feature.Wilderness,
         'Brasstown Wilderness Area', 'BR',
         'Blood Mountain Wilderness Area', 'BM',
         'Rich Mountain Wilderness Area', 'RM',
      '');
   }
   else if (sWild == 'CRRD') {
      return Decode($feature.Wilderness,
         'Mark Trail Wilderness Area', 'MT',
         'Raven Cliffs Wilderness Area', 'RC',
         'Tray Mountain Wilderness Area', 'RM',
      '');
   }
}

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];
}

return getResurveyLink();

Test Result

?itemID=2aab379ca46543e9a812ef07a387c802&field:District=BRRD&field:Wilderness_CRD=&field:
Wilderness_BRRD=BR&field:Wilderness_CRRD=&field:New_Site=no&field:
Date_Orig_Collection=2018-01-01T00:00:00-05:00&field:Campsite_ID_Number=2&field:
Dist_Along_Trail=&field:Date_Collected=2018-09-25T15:39:29-04:00&field:Ground_Dist=2&field:
Tree_Damage=2&field:Disturbed_Area=1&field:Overall_Imp=5&field:Between_Trail_Stream=&field:
Water_Source=3&field:Water_Dist_FT=60&field:Social_Trails=4&field:
Main_Trail_Designated=SystemTrail&field:Trail_Dist_FT=20&field:Impact_Area=2&field:
Litter_Trash=Heavy&field:Pot_Site_Expan=Medium&field:NNIS_Presence=Unknown&field:
Site_Condi=Fair&field:Rec_Site_S=Exists-GenSiteMaint&field:Admin_Structures=&
center=34.346803,-83.807537

Not sure what I'm doing wrong. I originally had null instead of blank strings in the Decode functions default value parameter, but switched them to test if that was the issue. Any help would be appreciated to get me on the right track. It seems like my logic is functional, but I've messed something up somewhere...

0 Kudos
3 Replies
ScottPrindle
Esri Regular Contributor

Hello Warren,

When you say you click on the pop-up and the link appears blank, where is this occurring? Is this in Survey123/Collector, the ArcGIS Online Map Viewer, or elsewhere? If the behavior is occurring in one of the native apps, can you verify that your Arcade Expression defined in the pop-up works within the Map Viewer?

What I'm hoping to understand with this line of questioning is: where is the expression being stripped from your pop-up? If you can define it through the Map Viewer and successfully view it there, then these calculations should be valid. If you can open the web map in a Web AppBuilder application (or other configurable Javascript API app), and the pop-up displays as expected, then we can infer that the Javascript API and your web map are behaving.

The arcgis-survey123:// URL scheme should function on a desktop if you have Survey123 installed locally. Installing the app on your desktop, and displaying the pop-up in the Map Viewer or a JS app (assuming these show the correct pop-up info) can help determine if your calculations and logic all check out and the resulting string is correctly used by Survey123.

Your description of the issue makes it sound like one of our apps (Collector maybe?) is not recognizing your complex calculations in Arcade Expressions. If this is the case, I would recommend testing these pop-ups in the Collector Aurora Project, and sharing your experiences on the Early Adopter Community.

Thanks,
Scott

FYI James Tedrick

WarrenCarver1
Emerging Contributor

Hey Scott,

No I have not used the complex expression in Collector. I was trying to get it to work in the Map Viewer. In Map viewer opening the table of for the layer the Attribute Expression is in shows a field for the calculation, but it is blank for each Point. If I click that point, the popup opens and has a link that I described above that should have a URL generated from my complex expression, but when I click said link the area that should be created from my expression is blank.

Since my first posting I have tinkered with it and it almost seems like the output string is simply too long to work??? If I keep all of the same code but simply have the final output (last return statement) a much shorter string the previously mentioned table and url link shows the appropriate string.

Because of this I stopped trying to have one complex expression and broke each field that actually required a calculation (Campsite_ID_Number, Campsite_Orig_Year, Location, District, Wilderness_CRD, Wilderness_BRRD, Wilderness_CRRD) into each of their own expressions. These are all working and showing up in the table with the expected output and when I click the link in the popup (in Map Viewer) the appropriate link is made, it opens survey 123, goes to the correct survey, fills out all the correct fields (including the correct location).

I got really excited at this point, saved my map, and launched Collector on an iPad and the link here does not work. It appears that the fields are not calculating and the survey is being passed a literal string of "{expression/expr5}" instead of a calculated value. If this is too separate of an issue I can create a new question for it, but I also haven't had a chance to search the forums to see if anyone else has had the same issue yet.

Anyways, I would love any further advice about the original issue of this post or the current one I just mentioned! I just got assigned to go help one of our field crews in a wilderness area for the next week as their down some staff, but once I get back to civilization, I can take some screenshots of what I'm noticing and post them, if it helps. Thank you!

ScottPrindle
Esri Regular Contributor

Hello Warren Carver,

I can't comment specifically about the initial issue with your complex expression, as I don't have an answer to those concerns without a lot more reading and . It's possible there is an issue with syntax, logic, or as you noted, the output string is too long. That's still undetermined, so I would wait for another poster to chime in if they see something about the initial issue.

With regards to your revamped approach of handling each calculation in its own expression, this will be a great way to isolate any problematic calculations and allow you to compartmentalize the whole thing. I'd recommend this approach at least in the beginning, because you can verify the work piece by piece rather than as one giant expression.

When you still see issues with your Arcade Expressions in Collector, are you working with Collector Classic (the current released version in the App Store) or Collector Aurora? Collector Classic will not support Arcade Expressions due to some runtime limitations, so this is going to be expected behavior. Collector Aurora is currently nearing the end of an open beta, but should support Arcade Expressions within the pop-up. Collector Aurora will be finalized and released in the next couple of months, so even if you are not interested in joining the beta, you will see support for Arcade Expressions soon.

I hope this information is helpful! Please let me know if you have better results in Collector Aurora, or if this issue has been occurring for you in the beta version as well.

Thanks,

Scott

0 Kudos