How to properly set values from database with SET()


I’m trying to build IVR. So, when user call first I’m setting the PIN code from DB and asking it to input it. After user input the code I’ve checked it against the PIN code in the database and if it is correct to proceed whit checking if there are any messages for the user. If there are messages I’m trying to SET them and play them.

The problem is that instead of messages it is set the PIN code.

Bellow, I’ll share this part from the dialplan and the output in order to understand me better.

        if("${DIGIT}" == "${PIN}") {
                if($["${ODBC_NEWMESSAGES}" != "0"]) {
                else {
        else {
              jump voice_en;

Here is what is happening

   -- Executing [119@internal:9] Goto("SIP/5634-00000139", "voice_en,1") in new stack
    -- Goto (internal,voice_en,1)
    -- Executing [voice_en@internal:1] NoOp("SIP/5634-00000139", "") in new stack
    -- Executing [voice_en@internal:2] Set("SIP/5634-00000139", "PIN=1234") in new stack
    -- Executing [voice_en@internal:3] Set("SIP/5634-00000139", "CHANNEL(language)=en") in new stack
    -- Executing [voice_en@internal:4] Playback("SIP/5634-00000139", "103") in new stack
       > 0x7f7abc01fbc0 -- Probation passed - setting RTP source address to aaa.bbb.ccc.ddd:17652
    -- <SIP/5634-00000139> Playing '103.slin' (language 'en')
    -- Executing [voice_en@internal:5] Read("SIP/5634-00000139", "DIGIT,,4") in new stack
    -- Accepting a maximum of 4 digits.
    -- User entered '1234'
    -- Executing [voice_en@internal:6] GotoIf("SIP/5634-00000139", "1?7:16") in new stack
    -- Goto (internal,voice_en,7)
    -- Executing [voice_en@internal:7] WaitExten("SIP/5634-00000139", "1") in new stack
    -- Timeout on SIP/5634-00000139, continuing...
    -- Executing [voice_en@internal:8] GotoIf("SIP/5634-00000139", "1?9:13") in new stack
    -- Goto (internal,voice_en,9)
    -- Executing [voice_en@internal:9] Set("SIP/5634-00000139", "MESSAGES=1234") in new stack
    -- Executing [voice_en@internal:10] Playback("SIP/5634-00000139", "1234") in new stack

This line is wrong:

-- Executing [voice_en@internal:9] Set("SIP/5634-00000139", "MESSAGES=1234") in new stack

1234 is the PIN code, not the amount of the messages from the database.

Please suggest me what is wrong here. Do I need to clear the PIN code somehow from SET() before trying to set new values?

No one has an idea how to fix this?

You haven’t provided the func_odbc configuration showing what the queries are like. You should also provide the output of “dialplan show” to show the actual dialplan in use.

This is the function query - ODBC_GETMESSAGES

readsql=SELECT recording FROM voicemessages WHERE mailboxuser='${SQL_ESC(${ARG1})}'


readsql=SELECT password FROM voicemail WHERE mailbox='${SQL_ESC(${ARG1})}'


readsql=SELECT count(mailboxuser) FROM voicemessages WHERE mailboxuser='${SQL_ESC(${ARG1})}'

About the dialplan - It is in my question. I’m using extension.ael

What you’ve provided is the extension.ael, but “dialplan show” presents it in the format that most people are used to. AEL itself isn’t commonly used.

Oh, sorry. I didn’t get that you want the CLI output of the dialplan:

[ Context 'internal' created by 'pbx_ael' ]
  '119' =>      1. NoOp()                                     [pbx_ael]
                    2. WaitExten(1)                               [pbx_ael]
                    3. Set(COUNT=${ODBC_EXIST(${CALLERID(num)})}) [pbx_ael]
                    4. WaitExten(1)                               [pbx_ael]
                    5. GotoIf($[${COUNT} != 0]?6:12)              [pbx_ael]
                    6. GotoIf($[${ODBC_LANG(${CALLERID(num)})} == "en"]?7:9) [pbx_ael]
                    7. Goto(voice_en,1)                       [pbx_ael]
                    8. Goto(10)                                   [pbx_ael]
                    9. Goto(voice_f,1)                       [pbx_ael]
                    10. NoOp(Finish if_if_internal_741_742)       [pbx_ael]
                    11. Goto(13)                                  [pbx_ael]
                    12. Playback(110)                             [pbx_ael]
                    13. NoOp(Finish if_internal_741)              [pbx_ael]
                    14. Hangup()                                  [pbx_ael]
  'voice_en' => 1. NoOp()                                     [pbx_ael]
                    2. Set(PIN=${ODBC_PINCHECK(${CALLERID(num)})}) [pbx_ael]
                    3. Set(CHANNEL(language)=en)                  [pbx_ael]
                    4. Playback(103)                              [pbx_ael]
                    5. Read(DIGIT,,4)                             [pbx_ael]
                    6. GotoIf($["${DIGIT}" == "${PIN}"]?7:16)     [pbx_ael]
                    7. WaitExten(1)                               [pbx_ael]
                    8. GotoIf($[!"${ODBC_NEWMESSAGES}"]?9:13)     [pbx_ael]
                    9. Set(MESSAGES=${ODBC_GETMESSAGES(${CALLERID(num)})}) [pbx_ael]
                    10. Playback(${MESSAGES})                     [pbx_ael]
                    11. VoicemailMain(${CALLERID(num)}@VoiceMail) [pbx_ael]
                    12. Goto(14)                                  [pbx_ael]
                    13. Playback(1475)                            [pbx_ael]
                    14. NoOp(Finish if_if_internal_743_744)       [pbx_ael]
                    15. Goto(17)                                  [pbx_ael]
                    16. Goto(voice_en,1)                      [pbx_ael]
                    17. NoOp(Finish if_internal_743)              [pbx_ael]

Fixed it. The problem was in this line

if($["${ODBC_NEWMESSAGES}" != "0"]) { ... }

should be

if(${ODBC_NEWMESSAGES(${CALLERID(num)})} != 0) { ... }
1 Like