Arcade Expression Cannot read property 'length' of undefined error

2892
14
Jump to solution
10-28-2020 05:59 AM
PaulSweeney3
Occasional Contributor III

Hi All 

See Acade expression 

Var polesLayer =  FeatureSetByPortalItem(Portal('myportal'), 'xxxxxxxxxx')
var chambers  = FeatureSetByPortalItem(Portal(''my portal'), 'xxxxxxxxxx')
Var buff = buffer($feature,1,'meters')
Var poles = Intersects(buff,polesLayer)
Var chambers  = Intersects(buff,chambers)
var cnt = count(poles)
var cntchambers = count(chambers) 
var popupResult = ''
for (var f in poles) {

popupResult += f.barcode + " to pole " 

}var ChambResult = ''
for (var f in chambers) {

ChambResult += f.label + " to chamber " 

}
var strLenght = count(popupResult)-8
var note = left(popupResult,strLenght)
var strLenght2 = count(ChambResult)-15
var note2 = left(ChambResult,strLenght2)
var popup = IIf(cnt==1, replace(("install subduct " + DomainName($feature,"sub_size")+ " from pole " +text(note)),'to pole',''), ("install subduct " + DomainName($feature,"sub_size")+ " from pole " +text(note)))
var popup2 = IIf(cntchambers==1, replace(("install subduct " + DomainName($feature,"sub_size")+ " from chamber " +text(note2)),'to chamber',''), ("install subduct " + DomainName($feature,"sub_size")+ " from chamber " +text(note2)))
var popup3 = "install subduct " + DomainName($feature,"sub_size")+" from the chamber "+ChambResult+" to the pole "+popupResult
var popup3 = replace(popup3,' to pole ',"")
var popup3 = replace(popup3,' to chamber ',"")
var finalresult = when(cnt <= 2 && cntchambers==0,popup,cnt == 0 && cntchambers==2, popup2,cnt == 1 && cntchambers==1, popup3,'n/a')
return finalresult‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 i am using this expression to check if a line is intersecting two point feature layers and return an expression to run a specific type of subduct between each feature. the expression works as expected in the pop up but when i try to run it in the field calculator it fails with the expression 

"Cannot read property 'length' of undefined error"

Tags (1)
0 Kudos
14 Replies
PaulSweeney3
Occasional Contributor III

HI @XanderBakker 

 

The field in question is "Test_Note , feel free to try, i tried previously in Pro but could not get it to work either. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

 

I will give it a shot later on and post back any results.  

XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

 

No luck here either, but I think it is due to the access to the pole and chambers featuresets. To compare in the pop-up the expression worked since I can access the layers from the map by their names. However, the map is not available in a Field Calculation and the chambers and poles are not in the same datastore. That is why I assume you tried to access the layers using FeatureSetByPortalItem. However, I don't think I am able to get access to these layers, since I am not part of the portal where the layers are stored.

When you try your expression in a pop-up and you access the layers using FeatureSetByPortalItem, does the expression work, or does it return an error. I noticed the error when I try and do a Count on the layer to see if it returned something and that throws an error in my case.

 

XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

 

I just did a test with the expression after copying the data to a local file gdb and ran the expression after changing the access by $datastore and the expression just works. It must be due to the portal access to the two layers that is causing the problem...

XanderBakker_0-1606776387628.png

 

 

PaulSweeney3
Occasional Contributor III

Thanks @XanderBakker it is working for me now and the good news is the pop up is working in the field maps app so i can use it in that for our field crews. Really appreciate the help on this , I  applaud your efforts to support everyone on this page with arcade quieres  it really is very helpful. Well done. 

0 Kudos