Select to view content in your preferred language

Arcade calculation works in Map Viewer but not Field Maps

763
2
Jump to solution
09-19-2024 11:44 AM
GISUser74305830
Regular Contributor

EDIT: I've isolated the problem to the Push function to supply the dictionary with the value. I can't see what I'm doing wrong here. Again, this works just fine in Map Viewer but not in Field Maps.

// Iterate through the filtered RCS, grab the Structure ID, convert it to a number, and then push it to the new Feature Set
for(var R in RCS_in_District){
var RCS_ID_txt = R['StructureID']
var RCS_ID_num = Number(RCS_ID_txt)

Push(
RCS_d["features"],
{
attributes: {
RCS_ID: RCS_ID_num,
},
},
)
}

 

 

This works just fine and dandy in Map Viewer but "fails to calculate" in Field Maps. Note that I am testing Field Maps online - I don't need a disconnected environment.

Goal: Use Arcade expression to autopopulate StructureID field in Road Class Structures with a unique sequential ID based upon the District it falls in.

Assumptions/Logic:

  • Road Class Structures is a line layer that the user draws
    • Contains field called "StructureID" (text). "StructureID" has the following naming convention:
      • <District #> + <3-digit sequential number> (i.e. the 347th Road Class Structure in District 3 gets a StructureID = 3347)
  • Tulsa County District Boundaries is a polygon layer of District Boundaries (3 total)
    • Contains field called "District" (text). Values are "1", "2", or "3"

Process:

  1. If User edits an existing Road Class Structure, the ID does not change.
  2. If User draws a new Road Class Structure
  3. Intersects the $feature against the District to get the District ID
  4. if it falls outside a District, it gets a value of "9999"
  5. If it falls inside a District:
    1. Filters all Road Class Structures whose Structure ID starts with the District #
    2. Creates a dictionary to store all the Structure IDs
    3. Iterates over the filtered Road Class Structures and populates the dictionary with the numerical equivalent of the Structure ID
    4. Returns a FeatureSet of the dictionary
    5. Sorts it by Structure ID descending
    6. Grabs the first value (which is the highest number)
    7. Highest number + 1
    8. Converts that to text and returns it
  6.  
0 Kudos
1 Solution

Accepted Solutions
GISUser74305830
Regular Contributor

I solved my problem - it has to do with the semi-colons and commas that I see strewn all throughout the various Arcade examples I've looked at. So naturally I adopted them in my own script. But a closer look at the syntax for Push() shows I had too many commas and semi-colons, so I took them out and - voila - it works.

 

This is what my Push function looked like before:

Push(
RCS_d["features"],
{
attributes: {
RCS_ID: RCS_ID_num,
},
},
)

 

And this is what I changed it to:

Push(
RCS_d["features"],
{
attributes: {
RCS_ID: RCS_ID_num
}
}
)

 

So, I guess a larger question is - what is the purpose of all these commas and semi-colons I see in Arcade examples? From what I understand every Arcade statement should have a semi-colon on the end, but is that a stylistic convention or is it strictly necessary? 

Anyways, my issue has been solved.

View solution in original post

0 Kudos
2 Replies
GISUser74305830
Regular Contributor

Would love to hear from any of the superstars out there:

@jcarlson

@XanderBakker 

0 Kudos
GISUser74305830
Regular Contributor

I solved my problem - it has to do with the semi-colons and commas that I see strewn all throughout the various Arcade examples I've looked at. So naturally I adopted them in my own script. But a closer look at the syntax for Push() shows I had too many commas and semi-colons, so I took them out and - voila - it works.

 

This is what my Push function looked like before:

Push(
RCS_d["features"],
{
attributes: {
RCS_ID: RCS_ID_num,
},
},
)

 

And this is what I changed it to:

Push(
RCS_d["features"],
{
attributes: {
RCS_ID: RCS_ID_num
}
}
)

 

So, I guess a larger question is - what is the purpose of all these commas and semi-colons I see in Arcade examples? From what I understand every Arcade statement should have a semi-colon on the end, but is that a stylistic convention or is it strictly necessary? 

Anyways, my issue has been solved.

0 Kudos