Hi Paul Sweeney ,
Sorry for the late reply but I was attending the IMGIS conference and yesterday was a national holiday.
I just changed your code slightly, but it is still not very convincing. A couple of comments:
- In your code do you have the layerID when you use FeatureSetByPortalItem for poles and chambers?
- The validation of the count is before you do the loop for both poles and chambers
- I am not convinced with the final When, since there are a number of cases that in theory can occur that are probably not accounted for. See lines 88 to 98 in the code below. Are those correct?
var LayerIdPoles = 0;
var polesLayer = FeatureSetByPortalItem(Portal('my portal'), 'xxxxxxxx', LayerIdPoles);
Console('polesLayer ' + polesLayer);
var LayerIdChambers = 0;
var chambers = FeatureSetByPortalItem(Portal('my portal'), 'xxxxxxxx', LayerIdChambers);
Console('chambers ' + chambers);
var buff = Buffer($feature, 0.1, 'meters');
var poles = Intersects(buff, polesLayer);
var cnt = Count(poles);
Console('cnt ' + cnt);
var chambers = Intersects(buff, chambers);
var cntchambers = Count(chambers);
Console('cntchambers' + cntchambers);
var popupResult = '_';
if (cnt>0) {
for (var f in poles) {
popupResult += f.barcode + " to pole ";
}
var strLenght = Count(popupResult) - 8;
Console('strLenght ' + strLenght);
var note = Left(popupResult, strLenght);
Console('note ' + note)
var popup = IIf(cnt==1,
Replace(
"install subduct " + DomainName($feature, "sub_size") + " from pole " + note,
'to pole',
''),
"install subduct " + DomainName($feature, "sub_size") + " from pole " + note);
Console('popup '+popup);
} else {
popupResult = "There is no Link required here";
var popup = "";
}
Console('popupresult ' + popupResult);
var ChambResult = '_';
if (cntchambers>0) {
for (var f in chambers) {
ChambResult += f.label + " to chamber " ;
}
var strLenght2 = Count(ChambResult) - 15;
Console('strLenght2 ' + strLenght);
var note2 = Left(ChambResult,strLenght2);
Console('note2 '+note2);
var popup2 = IIf(cntchambers==1,
Replace(
"install subduct " + DomainName($feature,"sub_size")+ " from chamber " + note2,
'to chamber',
''),
"install subduct " + DomainName($feature,"sub_size") + " from chamber " + note2);
Console('popup2 ' + popup2);
} else {
ChambResult = "There is no Link required here";
var popup2 = "";
}
Console('ChambResult ' + ChambResult);
var popup3 = "install subduct " + DomainName($feature,"sub_size") +
" from the chamber " + ChambResult + " to the pole " + popupResult;
Console('popup3 ' + popup3);
var popup3 = Replace(popup3,' to pole ', "");
Console('popup3 ' + popup3);
var popup3 = Replace(popup3,' to chamber ',"");
Console('popup3 '+popup3);
var finalresult = When(cnt <= 2 && cntchambers==0, popup,
cnt == 0 && cntchambers==2, popup2,
cnt == 1 && cntchambers==1, popup3,
'n/a');
Console('finalresult ' + finalresult);
return finalresult;
It is strange that if you only have a single feature, the expression works correctly but the field calculation fails. how are you filtering the featureset? Did you create a new source? It is possible that the pop-up validator is more forgiving than the one used in the field calculation...