Select to view content in your preferred language

Count function in Arcade Not working properly in Field Maps, always returns 1.

623
2
Jump to solution
06-29-2023 07:20 AM
Labels (1)
JohnSmoluk
New Contributor

I'm working on smart forms for a Field Maps map. There's an attribute called Block in a polygon layer, and it's a text string so that there can leading zeros for blocks 1-9. When someone adds a point inside the block, I want the Block number to auto-fill in the point attributes. I can get other attributes to auto-fill just fine. But for this, trying to use Count to know whether it is a single character or not, seems to not be working. It always adds a leading zero, no matter the number (e.g. 014, or 004 if the leading zero was already there). Looking for help on why the Count is not correctly counting the text characters.

First code attempt:

var block = FeatureSetByName($map, "Blocks")
var recordGUID = upper($feature.BlockGuid)
var subset = filter(block, `GlobalID = '${recordGUID}'`);
if (Count(subset) > 0) {
    if (Count(subset) == 1) {
    return Concatenate(["0", First(subset).Block])
    }
    else {
    return First(subset).Block
    }
}

Second code attempt:

var block = FeatureSetByName($map, "Blocks")
var recordGUID = upper($feature.BlockGuid)
var subset = filter(block, `GlobalID = '${recordGUID}'`);
var num = Count(subset)
if (num == 1){
  return Concatenate(["0", First(subset).Block])
}
else {
  return First(subset).Block
}
 
 
Thank you.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You're counting the number of records in the FeatureSet "subset". You need to get the attribute from that featureset and count the number of characters in it.

var block = FeatureSetByName($map, "Blocks")
var recordGUID = upper($feature.BlockGuid)
var subset = First(Filter(block, `GlobalID = '${recordGUID}'`));
if (!IsEmpty(subset) {
    if (Count(subset.Block) == 1) {
      return Concatenate(["0", subset.Block])
    }
    else {
      return subset.Block
    }
}

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

You're counting the number of records in the FeatureSet "subset". You need to get the attribute from that featureset and count the number of characters in it.

var block = FeatureSetByName($map, "Blocks")
var recordGUID = upper($feature.BlockGuid)
var subset = First(Filter(block, `GlobalID = '${recordGUID}'`));
if (!IsEmpty(subset) {
    if (Count(subset.Block) == 1) {
      return Concatenate(["0", subset.Block])
    }
    else {
      return subset.Block
    }
}
0 Kudos
JohnSmoluk
New Contributor

Aha! OK, I see what I did wrong there. Thank you very much, that worked!

0 Kudos