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:
Solved! Go to Solution.
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
}
}
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
}
}
Aha! OK, I see what I did wrong there. Thank you very much, that worked!