Select to view content in your preferred language

Arcade working on web map, but not in FM

224
2
05-31-2025 07:32 PM
CristianGraf
Emerging Contributor

Hello, 

Im trying to populate a field with sequentials numbers. This sequence it's grouped by an unique number (AKA Project Number). For any group of unique project number, it will create a sequential number 1 to X.

CODE
 _________________________________________________________________________________________________
if(IsEmpty($feature["POLE_NUMBER"]) || ($feature["POLE_NUMBER"])==0){
var np_1= null
if(IsEmpty($feature["numero_projet_correction"])){
np_1=$feature["numero_projet"]}
else {
$feature["numero_projet_correction"]}
var numberlist = FeatureSetByName($map,"Poteau (Lien Survey123)")
var num_proj = Filter(numberlist, "numero_projet = '" + np_1 + "'")
var num_proj_corr = Filter(numberlist, "numero_projet_correction = '" + np_1 + "'")
var counter = Count(num_proj)
var counter_corr = Count(num_proj_corr)
var id = counter+counter_corr+1

return id
}
else {
//Return existing value if null or different of 0
return $feature["POLE_NUMBER"]
}
__________________________________________________________________________________________________
 
I did try several versions, but I have always the same results...

Any suggestion?


 
Thank you so mutch!!!

 

0 Kudos
2 Replies
KerriRasmussen
Esri Contributor

Hi @CristianGraf. You mentioned that the expression doesn’t work in Field Maps, are you seeing an error or is it returning an incorrect number? What kind of results are you seeing? And when you say that it works in a webmap, are you using a form or are you seeing the correct number in a pop-up?

0 Kudos
NathanDavis
Occasional Contributor

A couple things:

1. The 'else' here doesn't do anything:

if(IsEmpty($feature["numero_projet_correction"])){
np_1=$feature["numero_projet"]}
else {
$feature["numero_projet_correction"]}
 
I think your intent in the else clause is to cast $feature["numero_projet_correction"] to np_1
 
*Fix*
You could change this to:
var np_1 = IIf(!IsEmpty($feature["numero_projet"]), $feature["numero_projet"], $feature["numero_projet_correction"])

 

2. I think your filter functions may be broken, and therefore not returning any records to 'num_projet' and 'num_projet_corr'.  The Filter functions uses a SQL92 expression, with use of the '@' symbol to use variables in the arcade.  

The filter expression for 'num_project' is currently:

"numero_projet = '" + np_1 + "'"

But the SQL92 expression for this filter is:
`numero_project = @NP_1`

Likewise for numero_projet_corr:

`numero_projet_corr = @NP_1`

--- Optimizing this calc --- Extra

If you want to improve the efficiency of this calculation, consider nesting the featureSet based calls, which result in more traffic.  For your code, you're making 3 calls to the feature:
- FeatureSetByName
- Filter
- Filter
** i don't remember if Count hits the featureSet, but if it does, you'd be making 5.

If you'd like to simplify your code, you could replace this section:

----
var numberlist = FeatureSetByName($map,"Poteau (Lien Survey123)")
var num_proj = Filter(numberlist"numero_projet = '" + np_1 + "'")
var num_proj_corr = Filter(numberlist"numero_projet_correction = '" + np_1 + "'")
var counter = Count(num_proj)
var counter_corr = Count(num_proj_corr)
var id = counter+counter_corr+1

return id
----
with this:
---
  var id = Count(
    Filter(
      FeatureSetByName(
        $map,
        "Poteau (Lien Survey123)"
      ),
    `numero_project = @NP_1 OR numero_project_corr = @NP_1`
    )
  )

---

** Code Block with all corrections: **

var initPoleID = $feature["POLE_NUMBER"]

if (IsEmpty(initPoleNum) || initPoleNum == 0) {
  var np_1 = IIf(!IsEmpty($feature["numero_projet"]), $feature["numero_projet"], $feature["numero_projet_correction"])
  var numberlist = FeatureSetByName($map, "Poteau (Lien Survey123)")
  var poleID = Count(
    Filter(
      FeatureSetByName(
        $map,
        "Poteau (Lien Survey123)"
      ),
    `numero_project = @NP_1 OR numero_project_corr = @NP_1`
    )
  )
  return poleID + 1
} else {
  //Return existing value if null or different of 0
  return initPoleNum
}
0 Kudos