I need help creating a arcade expression for a Attribute Calculation Rule that calculates the values from one field (Parcel Identification Number) whose values are separated by spaces, into three different fields (Map Book Page, Block/Landlot Number, and Parcel ID Number). The only problem is that the values in the Parcel Identification Number field that I'm attempting to calculate to the other fields are separated by spaces which are inconsistent as far as how many spaces there may be between the values. It's accounting for these inconsistencies in the amount of spaces that I'm not sure how to deal with. Any help is greatly appreciated.
Thanks,
Robert.
ArcGIS Pro 3.3.1
Currently working with this data is test fgdb, but will move the data and attribute rule to an Enterprise GDB.
Solved! Go to Solution.
Based on Mike's comment about the return edits dictionary, I was able to figure that part out. However, looking deeper into the data, I noticed that some of the BLKLLPARCELID fields were blank. So, with the help of ESRI tech support, this is the solution that we ended up with.
// Get the value from ParcelNumber and normalize spaces
// Remove trailling space and extra space
var parcelValue = Trim($feature.PARCELID)
var Maxspace = 10;
var result = 0
for(var z=0; z < Maxspace; z++) {
parcelValue = Replace(parcelValue, " ", " ")
}
// Split the normalized ParcelNumber value into parts
var parts = Split(parcelValue, " ")
var Map
var Block
var Parcel
// Extract values for Map, Block, and Parcel
if ( count(parts) == 2 ) {
Map = parts[0]
Block = null
Parcel = parts[1]
}
else if ( count(parts) == 3 ) {
Map = parts[0]
Block = parts[1]
Parcel = parts[2]
}
// Return the results as updated attributes
return {
"result": {
"attributes": {
"PAGEPARCELID": Map,
"BLKLLPARCELID": Block,
"LOWPARCELID": parcel
}
}
}
Thanks to Nazrita Antasha with ESRI support Services for helping with this attribute rule.
Robert.
Is this what you are trying to do?
var val = "5 1 600"
var split_vals = Split(val, ' ')
var trimed_vals = []
for (var i in split_vals)
{
if (IsEmpty(split_vals[i])){
continue
}
Push(trimed_vals, split_vals[i])
}
return trimed_vals
produces
Thanks for your response Mike.
This is what I initially came up with based on what was generated from ChatGTP.
// Split the Parcel Identification Number (PARCELID) value by spaces
var parts = Split($feature["PARCELID"], " ")
//Calculate values based on the parts
var Map = IIf(Count(parts) > 0, Number(parts[0]), null)
var Land = IIf(Count(parts) > 1, Number(parts[1]), null)
var PID = IIf(Count(parts) > 2, Number(parts[2]), null)
//Return the results as a object
return {
"Map": $feature.PAGEPARCELID,
"Land": $feature.BLKLLPARCELID,
"PID": $feature.LOWPARCELID
}
However, I get this error message even though the expression validates successfully.
So, I started creating sperate attribute rules for each field that I'm trying to update. This code below updates the PAGEPARCELID field (Map Book Page). It works ok and updates when a change is made to the PARCELID field (Parcel Identification Number field).
// Get the value from parcelID
var parcelValue = $feature["PARCELID"]
// Find the index of the first space
var spaceIndex = Find(" ", parcelValue)
// Extract all characters before the first space
var mapValue = IIf(spaceIndex != -1, Left(parcelValue, spaceIndex), parcelValue)
// Return the result for the Map field
mapValue
The following code updates the BLKLLPARCELID (Block/Landlot Number field) when a change is made to the PARCELID field.
// Get the value from the PIN field and normalize spaces
var pinValue = Trim(Replace($feature["PARCELID"], " +", " "))
// Split the normalized PIN value into parts
var parts = Split(pinValue, " ")
// Extract the second array element (Block)
var Block = IIf(Count(parts) > 1, parts[1], null)
// Return the Block value
Block
When I try to validate this expression to calculate the the LOWPARCELID (Parcel ID Number field) based on the last characters in the Parcel Identification Number field, I get a Unknown function error on line 5.
// Get the value from parcelID and trim leading/trailing spaces
var parcelValue = Trim($feature["PARCELID"])
// Find the index of the last space
var lastSpaceIndex = LastIndexOf(parcelValue, " ")
// Extract all characters after the last space
var LOW = IIf(lastSpaceIndex != -1, Right(parcelValue, TextLength(parcelValue) - lastSpaceIndex - 1), parcelValue)
// Return the result for the LOW field
LOW
Thanks,
Robert.
you need to use the proper return edits dictionary, more info here:
please do not break this into multiple attribute rules. There is a cost to each rule
My goal is to have one single rule.
Based on Mike's comment about the return edits dictionary, I was able to figure that part out. However, looking deeper into the data, I noticed that some of the BLKLLPARCELID fields were blank. So, with the help of ESRI tech support, this is the solution that we ended up with.
// Get the value from ParcelNumber and normalize spaces
// Remove trailling space and extra space
var parcelValue = Trim($feature.PARCELID)
var Maxspace = 10;
var result = 0
for(var z=0; z < Maxspace; z++) {
parcelValue = Replace(parcelValue, " ", " ")
}
// Split the normalized ParcelNumber value into parts
var parts = Split(parcelValue, " ")
var Map
var Block
var Parcel
// Extract values for Map, Block, and Parcel
if ( count(parts) == 2 ) {
Map = parts[0]
Block = null
Parcel = parts[1]
}
else if ( count(parts) == 3 ) {
Map = parts[0]
Block = parts[1]
Parcel = parts[2]
}
// Return the results as updated attributes
return {
"result": {
"attributes": {
"PAGEPARCELID": Map,
"BLKLLPARCELID": Block,
"LOWPARCELID": parcel
}
}
}
Thanks to Nazrita Antasha with ESRI support Services for helping with this attribute rule.
Robert.