Arcade Expression Split() Runtime Error Out of Bounds

79
4
08-17-2022 07:20 AM
Labels (1)
KWilliams
New Contributor II

Hello - I have a string value that consists of three data elements that are separated by a space then comma. Essentially looks like "workorder ,siteID ,fqnid". I intend on populating their individual fields with their coordinating element using the Split() function. I had a test feature where I sorted this all out, and it worked flawlessly. Now I'm trying to deploy to the field collection devices and I'm getting errors (*sigh* 🙄 love GIS)

Runtime Error: Out of Bounds

First set of code to get the workorder element, which does work:

var concat = split($feature["WO_SiteID_FQNID"], " ,")

return concat[0]

Perfect! Until...I try to write the next two elements into their coordinating fields SiteID  and FQNID, it fails. The coding is identical except for which element I'm pulling [1] or [2]

'out of bounds' seems to imply that I don't have data in that second or third position, but I definitely do. 

KWilliams_0-1660744957888.png

Any help would be greatly appreciated!!

 

Thanks

0 Kudos
4 Replies
jcarlson
MVP Notable Contributor

Can you give some example values of this field? And are you certain that there are no values present in which splitting by "," would only result in 2 or fewer items in the array?

Generally, you should assume that there will be weird data in your field and try to code for it. In this case, you might want to check the Count(concat) value, and only proceed if that value is > 2.

- Josh Carlson
Kendall County GIS
0 Kudos
KWilliams
New Contributor II

Hello,

thanks for replying so quickly!

Here's some examples. All value options have three elements that are separated by comma's.  

1904CIQI - 1904CIQI ,H1001 ,FIB:AER::500041931

1902DXFX - 1711ARZG.13 ,BH_HUTTO_SOUTH_SUN_CITY_NORTH ,FIB:AER::121059523

1901DLCI - 1710AKYS.1 ,KM49 ,FIB:AER::121098187

 

There's 78 of these types of values. There's no other comma's in any of the string elements, I made sure of that ahead of time and just double checked that now. 

 

end goal is to auto-populate these three fields based on this singular selection which will help eliminate field operation typos who are not keen on using drop down menus.

 

thanks!

0 Kudos
jcarlson
MVP Notable Contributor

Hm. Inputting your sample values, I don't see any problem splitting the string and calling the separate items. Here's the expression I used to test:

 

var a = [
    '1904CIQI - 1904CIQI ,H1001 ,FIB:AER::500041931',
    '1902DXFX - 1711ARZG.13 ,BH_HUTTO_SOUTH_SUN_CITY_NORTH ,FIB:AER::121059523',
    '1901DLCI - 1710AKYS.1 ,KM49 ,FIB:AER::121098187',
    'breaking, string'
]

for (var b in a){
    
    Console(`splitting "${a[b]}"`)
    
    var concat = Split(a[b], ',')
    
    if(Count(concat) < 3){
        Console(`\t${a[b]} can't be split into at least 3 items`)
    } else {
        Console(`\t0: ${concat[0]}`)
        Console(`\t1: ${concat[1]}`)
        Console(`\t2: ${concat[2]}`)
    }
}

 

And the output:

splitting "1904CIQI - 1904CIQI ,H1001 ,FIB:AER::500041931"
	0: 1904CIQI - 1904CIQI 
	1: H1001 
	2: FIB:AER::500041931
splitting "1902DXFX - 1711ARZG.13 ,BH_HUTTO_SOUTH_SUN_CITY_NORTH ,FIB:AER::121059523"
	0: 1902DXFX - 1711ARZG.13 
	1: BH_HUTTO_SOUTH_SUN_CITY_NORTH 
	2: FIB:AER::121059523
splitting "1901DLCI - 1710AKYS.1 ,KM49 ,FIB:AER::121098187"
	0: 1901DLCI - 1710AKYS.1 
	1: KM49 
	2: FIB:AER::121098187
splitting "breaking, string"
	breaking, string can't be split into at least 3 items
- Josh Carlson
Kendall County GIS
0 Kudos
KWilliams
New Contributor II

Thank you for confirming that my split() should be working and its not some obvious coding issue I'm missing. I'll have to do some more digging into the issue. I know for the test environment where it worked flawlessly, that point layer was the only layer. In the live environment, there's 5+ other layers of data. Does that affect the way I call the $feature? Thank you for your assistance.

0 Kudos