Select to view content in your preferred language

Arcade expression fails at $layer profile

223
2
06-20-2024 11:32 AM
Labels (2)
KristalWalsh
Occasional Contributor II

Hi all, this is the code I am working with but I can't get past Line 3. This code worked like a charm in my old web map but I had to republish the web layers in a new map with revised schema and now it doesn't work. I've checked all the editing settings which are correct but I'm not sure how I need to fix my Playground error "$layer is not defined".  Note: This relational database is in design, so no feature data yet. Basically, when the customer feature is created the CustomerID is populated and then sequenced as below.  As I mentioned, it was working in the old map. I'm not sure where or what to check now and I can't find any examples of using $layer in all the resources on line. Would be very grateful for some advice on this! @bbollin 

@KenBuja would  you be able to point me in the direction of troubleshooting why my $layer is not defined? 

Thank you, Kristal 

var custID = $feature.CustomerID
var numArr = []
Console($layer)

if (IsEmpty(custID)) {
  if (Count($layer)>0){
    for (var row in $layer) {
      //Console (row ['CustomerID'])
      //return row ['CustomerID']
      if (!IsEmpty(row.CustomerID)) {
        var cn = Number(Split(row.CustomerID, 'C')[1])
        Console("Split number = " + Text (cn))
        Push(numArr, cn)
      }  
  }
  custID = "C" + Text(Max(numArr) + 1)
}
if (Count($layer)== 1) {
  custID = "C1"
  }
 }
 return custID

 

Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Playground doesn't use a profile where you can use $layer. If you click on "Profile variables", it only shows "$feature".

Snag_af67ee.png

You'll have to test out your code in a web map where you have access to more profile variables.

Snag_b1067b.png

 

KristalWalsh
Occasional Contributor II

I saw that and wasn't sure if that was indicating some problem. I understand though and have tested it in the Web Map but not sure where to look for a problem since this worked in my other map. Is there a different way to define the layer that I'm not thinking about? I understood that $layer should be specific to the layer (and all the features) of the field where the expression is being written.

Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
0 Kudos