List Iteration?

Is there a way to iterate over a list/hash/array in the dialplan? For example I have a sql table that returns a list of stations to try, I need to dial the first one, if it fails then the next and so on until one works or the list is empty. I see how I can do it with math, start at digit 1, setup a while loop and keep increasing the digit, but if a comma (or colon, semicolon, etc…) separated list is returned (in one string), how do I retrieve each item on the list one at a time? (like a “for” statement in most programming languages) or is this not possible? Thanks! - Jeremy

${CUT()}

You can use the FIELDQTY function to find how many delimiters you have and then walk through your variable with CUT.

Here is some old 1.4 Dialplan where I did this:

[code]
exten => s,1,NoOP
exten => s,n,Set(position=1)
exten => s,n,Set(max=${FIELDQTY(locations,-)})
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(PROMPT),Background(orgconfig/you-have)
exten => s,n,Saydigits(${max})
exten => s,n,background(orgconfig/locations-enter)
exten => _[1-9]!,1,ExecIf($[${max} >= ${EXTEN}]|Macro|orgconfig,${Org},${CUT(locations,${EXTEN})})
exten => _[1-9]!,2,Goto(ERROR,1)

; Read out the locations and what to press for each
exten => 0,1,NoOP
exten => 0,n,Set(pos=1)
exten => 0,n,While(${CUT(locations,${pos})})
exten => 0,n,Playback(orgconfig/location-number)
exten => 0,n,SayDigits(${pos})
exten => 0,n,SayPhonetic(${CUT(locations,${pos})})
exten => 0,n,Set(pos=${MATH(${pos}+1,int)})
exten => 0,n,EndWhile
exten => 0,n,Goto(s,PROMPT)[/code]

[quote=“johnkiniston”]You can use the FIELDQTY function to find how many delimiters you have and then walk through your variable with CUT.
[/quote]

Ah, got it. Use FIELDQTY to get the count and use CUT to get the item, I was looking for a single command and googleing for a example and nothing came up, just looking in the wrong place. I already am using a number loop, I just need to modify it slightly. I am doing a sql query on the number to get the text, this would be much better to return the full string and grab it from the string. Thanks! - Jeremy