Select to view content in your preferred language

Arcade Popup Expression Not working in Field Maps

1595
6
10-17-2024 12:32 PM
JCGuarneri
Frequent Contributor

I'm working on an Arcade content block expression for a popup that will be viewed in Field Maps. The goals are to show a link to a CW inspection or work order that needs to be completed (if applicable), and to display a table summarizing previous work on that asset. It works great in the map viewer, but does not work in Field Maps. Interestingly, the link fails completely, but the table will draw only the header row. I've split those two functions into different content blocks so I'm only dealing with one issue at  a time. I've included screenshots and code snippets below. Anyone have an idea how to get that to work? I know I can get the hyperlink to work if I just pass it as a hyperlink in a text block, but that removes the "only show it if applicable" logic. The table is what really mystifies me, as the header displays just fine.

For reference, I'm on  Enterprise 11.1 and Field Maps 24.2.1

JCGuarneri_2-1729193367619.png

 

JCGuarneri_1-1729192941980.jpeg

 

Here is my code for the link:

 

//get open hydrant inspections
var currentInspections = FeatureSetByName($map, "Open Hydrant Dry Checks",['InspectionId']);
//find the inspection that matches this hydratn
var cwID = $feature.CW_ID;
var query = `FeatureUid = '${cwID}'`;
var inspNow = Filter(currentInspections,query);
//base url
var baseURL = "cityworks11://openWorkActivity?workActivityType=2&workActivityId=";
//if there is an inspection, create link
If(Count(inspNow)>0){
var inspectionID = First(inspNow)["InspectionId"];
var inspURL = baseURL + inspectionID;
var linkText = `<a href="${inspURL}" >Complete Dry Check Inspection In Cityworks Mobile</a>`;
}
//if not, return a blank line
else{
  var linkText = ``;
}
return { 
	type : 'text', 
	text : linkText //this property supports html tags 
}

 

 

And here is the code for the table:

 

//get previous inspections and find those that are for this hydrant
var prevInspections = FeatureSetByName($map, "Previous Hydrant Inspections",['InspectionId','InspTemplateName','InspDate','ObservationSum','FeatureUid']);
var cwID = $feature.CW_ID;
var query = `FeatureUid = '${cwID}'`;
var relInspections = OrderBy(Filter(prevInspections,query), 'InspDate DESC');

//start HTML text with table header
var baseText = `<table>
<tr>
<th align = "left" width = "100">Date</th>
<th align = "left" width = "120">Inspection Type</th>
<th>Summary</th>
</tr>
`

//build table with alternating color rows
count = 1;
for(var i in relInspections){
  var inspDate = `${Month(i.InspDate)}/${Day(i.InspDate)}/${Year(i.InspDate)}`;
  var inspType = Decode(i.InspTemplateName,"Hydrant Dry Check Inspection",'Dry Check',"Hydrant Wet Check Inspection","Wet Check","Other");
  var color = IIf(count%2==0 , '#ffffff', '#e6e6e6');
  count += 1;

  var newRow = `<tr style = "background-color:${color}">
<td>${inspDate}</td>
<td>${inspType}</td>
<td>${i.ObservationSum}</td>
</tr>`;
baseText += newRow;
}
//finish HTML text
baseText += `</table>`;
return { 
	type : 'text', 
	text : baseText
}

 

 

 

 

0 Kudos
6 Replies
JCGuarneri
Frequent Contributor

Some additional testing reveals that I can add a single dummy row in by using hard coded values, but only outside of the for loop. Inside the for loop, the rows are not getting added, but it works fine outside of the loop. So the following code results in this in map viewer:

JCGuarneri_0-1729194395796.png

and this in Field Maps:

JCGuarneri_1-1729195221638.jpeg

 

 

 

//start HTML text with table header
var baseText = `<table>
<tr>
<th align = "left" width = "100">Date</th>
<th align = "left" width = "120">Inspection Type</th>
<th>Summary</th>
</tr>
`

baseText += `<tr style = "background-color:#e6ff03">
<td>1/1/2024</td>
<td>Wet Check</td>
<td>This inspection never happened</td>
</tr>`;
//build table with alternating color rows
count = 1;
for(var i in relInspections){
  var inspDate = `${Month(i.InspDate)}/${Day(i.InspDate)}/${Year(i.InspDate)}`;
  var inspType = Decode(i.InspTemplateName,"Hydrant Dry Check Inspection",'Dry Check',"Hydrant Wet Check Inspection","Wet Check","Other");
  var color = IIf(count%2==0 , '#ffffff', '#e6e6e6');
  count += 1;

  var newRow = `<tr style = "background-color:${color}">
<td>${inspDate}</td>
<td>${inspType}</td>
<td>${i.ObservationSum}</td>
</tr>`;
baseText += newRow;
baseText += `<tr style = "background-color:#e6ff03">
<td>1/1/2024</td>
<td>Wet Check</td>
<td>This inspection never happened</td>
</tr>`;
}
//finish HTML text
baseText += `</table>`;

 

0 Kudos
ChristopherCounsell
MVP Regular Contributor
var currentInspections = FeatureSetByName($map, "Open Hydrant Dry Checks",['InspectionId']);
//find the inspection that matches this hydratn
var cwID = $feature.CW_ID;
var query = `FeatureUid = '${cwID}'`;
var inspNow = Filter(currentInspections,query);

 

It looks like you are making a featureset and getting one field - InspectionID - but then filtering the featureset by another field, FeatureUid? I'm imagining this will cause issues unless it's always included in the feature set results.

Do you get any issues if you return the results within a text block as an expression, instead of an arcade block?

Can you go to the Field Maps logs or interact with the error? It could give more insight, e.g. I've seen this before when the expression hasn't returned a result for the feature. Because a correct return wasn't provided it throws an error. The logs identified this.

 

JCGuarneri
Frequent Contributor

That's a good catch, and a symptom of copy/pasting code from another layer. Interestingly, it still seems to return the correct result whether or not I explicitly include the FeatureUid field:

JCGuarneri_0-1729249952120.png

I did try explicitly including it and it still errors out on the Field Maps side. I also tried hardcoding a URL to our company web site, and Field maps still doesn't like it. It looks like field maps has trouble with the <a> HTML tag, even though that's listed as supported HTML.

I also realized I pasted the wrong code in for the table portion. I've corrected that now if you are interested in that as well.

0 Kudos
ChristopherCounsell
MVP Regular Contributor

We use the <a> tag without issues.

Is it because you're trying to open an app that may not be approved on iOS and Android stores?

https://doc.arcgis.com/en/survey123/get-started/integrate-launchanotherapp.htm

I'm not sure that short URLs to open another app would work for Citi works.

0 Kudos
JCGuarneri
Frequent Contributor

I don't think that's it. The Cityworks URL works fine for me in a slightly different context. Our current way to handle this is to have a popup on the inspection feature layer. The popup has an expression that builds the URL string, which is returned as text and fed to a hyperlink in a text popup element. I built this back in the old map builder and it works just fine. What's funny is that it doesn't work when I bypass that and just go straight for <a>.

Is the <a> tag working for you in Field Maps? And what version of Enterprise are you on?

0 Kudos
James_Whitacre_PGC
Regular Contributor

@JCGuarneri I am having this same exact issue and I cannot figure out what is going on. However, there is one main difference...and it is weird. If a record has a null date value in the date field, Field Maps will show any records with a null date field in the HTML table. The other strange thing, though, is that when I remove the date field values from the HTML table, it still doesn't work, but still shows the null date records. It is almost like there is an issue with the Feature Set and date fields in Field Maps. Maybe something is getting encoded incorrectly and not rendering properly?

I am on ArcGIS Enterprise 11.3 and Field Maps 24.3.0

 

0 Kudos