Setting a global variable to be used in my plan.. Issue


#1

*0 = off
*1 = on
*2 = current status

use global variable IVRONOFF to store this value during the day (so not per call)

exten => *1,1,Set(IVRONOFF=1)
exten => *1,n,Playback(custom/het_telefoonmenu_staat_nu_aan)
exten => *1,n,NoOp(${IVRONOFF})
exten => *1,n,Hangup()
exten => *0,1,Set(IVRONOFF=0)
exten => *0,n,Playback(custom/het_telefoonmenu_staat_nu_uit_en_gaat_automatisch_aan)
exten => *0,n,NoOp(${IVRONOFF})
exten => *0,n,Hangup()
exten => *2,1,NoOp(${IVRONOFF})
exten => *2,n,GotoIf($[${IVRONOFF}=0] ?:lbl_vdp-outbound_0)
exten => *2,n,Playback(custom/het_telefoonmenu_staat_aan)
exten => *2,n,Hangup()
exten => *2,n(lbl_vdp-outbound_0),Playback(custom/het_telefoonmenu_staat_uit_en_gaat_automatisch_aan)
exten => *2,n,Hangup()

Checking the verbose output

FREEPBX*CLI> core set verbose 3
Console verbose was OFF and is now 3.
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [*1@from-internal:1] Set(“SIP/702-00000141”, “IVRONOFF=1”) in new stack
– Executing [*1@from-internal:2] Playback(“SIP/702-00000141”, “custom/het_telefoonmenu_staat_nu_aan”) in new stack
– <SIP/702-00000141> Playing ‘custom/het_telefoonmenu_staat_nu_aan.slin’ (language ‘nl’)
– Executing [*1@from-internal:3] NoOp(“SIP/702-00000141”, “1”) in new stack
– Executing [*1@from-internal:4] Hangup(“SIP/702-00000141”, “”) in new stack
== Spawn extension (from-internal, *1, 4) exited non-zero on ‘SIP/702-00000141’
– Executing [h@from-internal:1] Macro(“SIP/702-00000141”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/702-00000141”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [s@macro-hangupcall:3] ExecIf(“SIP/702-00000141”, “0?Set(CDR(recordingfile)=)”) in new stack
– Executing [s@macro-hangupcall:4] NoOp(“SIP/702-00000141”, " monior file= ") in new stack
– Executing [s@macro-hangupcall:5] AGI(“SIP/702-00000141”, “attendedtransfer-rec-restart.php,”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/attendedtransfer-rec-restart.php
– <SIP/702-00000141>AGI Script attendedtransfer-rec-restart.php completed, returning 0
– Executing [s@macro-hangupcall:6] Hangup(“SIP/702-00000141”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 6) exited non-zero on ‘SIP/702-00000141’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/702-00000141’
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [*0@from-internal:1] Set(“SIP/702-00000142”, “IVRONOFF=0”) in new stack
– Executing [*0@from-internal:2] Playback(“SIP/702-00000142”, “custom/het_telefoonmenu_staat_nu_uit_en_gaat_automatisch_aan”) in new stack
– <SIP/702-00000142> Playing ‘custom/het_telefoonmenu_staat_nu_uit_en_gaat_automatisch_aan.slin’ (language ‘nl’)
– Executing [*0@from-internal:3] NoOp(“SIP/702-00000142”, “0”) in new stack
– Executing [*0@from-internal:4] Hangup(“SIP/702-00000142”, “”) in new stack
== Spawn extension (from-internal, *0, 4) exited non-zero on ‘SIP/702-00000142’
– Executing [h@from-internal:1] Macro(“SIP/702-00000142”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/702-00000142”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [s@macro-hangupcall:3] ExecIf(“SIP/702-00000142”, “0?Set(CDR(recordingfile)=)”) in new stack
– Executing [s@macro-hangupcall:4] NoOp(“SIP/702-00000142”, " monior file= ") in new stack
– Executing [s@macro-hangupcall:5] AGI(“SIP/702-00000142”, “attendedtransfer-rec-restart.php,”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/attendedtransfer-rec-restart.php
– <SIP/702-00000142>AGI Script attendedtransfer-rec-restart.php completed, returning 0
– Executing [s@macro-hangupcall:6] Hangup(“SIP/702-00000142”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 6) exited non-zero on ‘SIP/702-00000142’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/702-00000142’
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [*2@from-internal:1] NoOp(“SIP/702-00000143”, “1”) in new stack
– Executing [*2@from-internal:2] GotoIf(“SIP/702-00000143”, “0 ?:lbl_vdp-outbound_0”) in new stack
– Goto (from-internal,*2,5)
– Executing [*2@from-internal:5] Playback(“SIP/702-00000143”, “custom/het_telefoonmenu_staat_uit_en_gaat_automatisch_aan”) in new stack
– <SIP/702-00000143> Playing ‘custom/het_telefoonmenu_staat_uit_en_gaat_automatisch_aan.slin’ (language ‘nl’)
– Executing [*2@from-internal:6] Hangup(“SIP/702-00000143”, “”) in new stack
== Spawn extension (from-internal, *2, 6) exited non-zero on ‘SIP/702-00000143’
– Executing [h@from-internal:1] Macro(“SIP/702-00000143”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/702-00000143”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [s@macro-hangupcall:3] ExecIf(“SIP/702-00000143”, “0?Set(CDR(recordingfile)=)”) in new stack
– Executing [s@macro-hangupcall:4] NoOp(“SIP/702-00000143”, " monior file= ") in new stack
– Executing [s@macro-hangupcall:5] AGI(“SIP/702-00000143”, “attendedtransfer-rec-restart.php,”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/attendedtransfer-rec-restart.php
– <SIP/702-00000143>AGI Script attendedtransfer-rec-restart.php completed, returning 0
– Executing [s@macro-hangupcall:6] Hangup(“SIP/702-00000143”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 6) exited non-zero on ‘SIP/702-00000143’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/702-00000143’

When starting the gotoif (via *2), it seems that the IVRONOFF variable is back to 1 although I expected this to remain 0 (due to the previous action)

-- Executing [*2@from-internal:1] NoOp("SIP/702-00000143", "1") in new stack

Where do I go wrong in this issue ? ?


#2

You have set a local variable, not a global one. You need the GLOBAL “function” to set global variables.


#3

I will change it back to a GLOBAL variable, which I had before, but this was at that time also not succesfull. Keep you updated.


#4

The Global situation seems to be resolved

-- Executing [*0@from-internal:1] NoOp("SIP/702-00000192", "1") in new stack
-- Executing [*0@from-internal:2] Set("SIP/702-00000192", "GLOBAL(IVRONOFF)=0") in new stack

== Setting global variable ‘IVRONOFF’ to ‘0’

via

exten => *0,1,NoOp(${IVRONOFF})
exten => *0,n,Set(GLOBAL(IVRONOFF)=0)
exten => *0,n,NoOp(${IVRONOFF})
exten => *0,n,Playback(custom/het_telefoonmenu_staat_nu_uit_en_gaat_automatisch_aan)
exten => *0,n,NoOp(${IVRONOFF})
exten => *0,n,Hangup()

But stil have an issue using this variable in a gotoif statement… Tried various syntax but no succes

exten => *2,n,GotoIf([${IVRONOFF}=0] ?:lbl_vdp-outbound_0)

exten => *2,1,NoOp(${IVRONOFF})
exten => *2,n,GotoIf($[${IVRONOFF}=0] ?:lbl_vdp-outbound_0)
exten => *2,n,Playback(custom/het_telefoonmenu_staat_aan)
exten => *2,n,Hangup()
exten => *2,n(lbl_vdp-outbound_0),Playback(custom/het_telefoonmenu_staat_uit_en_gaat_automatisch_aan)
exten => *2,n,Hangup()

exten => *2,n,GotoIf([${IVRONOFF}=0] ?:lbl_vdp-outbound_0)

Results in:
– Executing [*2@from-internal:1] NoOp(“SIP/702-00000191”, “1”) in new stack
– Executing [*2@from-internal:2] GotoIf(“SIP/702-00000191”, “[1=0] ?:lbl_vdp-outbound_0”) in new stack
– Executing [*2@from-internal:3] Playback(“SIP/702-00000191”, “custom/het_telefoonmenu_staat_aan”) in new stack
– <SIP/702-00000191> Playing ‘custom/het_telefoonmenu_staat_aan.slin’ (language ‘nl’)
– Executing [*2@from-internal:4] Hangup(“SIP/702-00000191”, “”) in new stack

Or

-- Executing [*2@from-internal:1] NoOp("SIP/702-00000193", "0") in new stack
-- Executing [*2@from-internal:2] GotoIf("SIP/702-00000193", "[0=0] ?:lbl_vdp-outbound_0") in new stack
-- Executing [*2@from-internal:3] Playback("SIP/702-00000193", "custom/het_telefoonmenu_staat_aan") in new stack
-- <SIP/702-00000193> Playing 'custom/het_telefoonmenu_staat_aan.slin' (language 'nl')
-- Executing [*2@from-internal:4] Hangup("SIP/702-00000193", "") in new stack

I expect the Goto if to swith on the value to Step 2,5 or to continue to step 3. But the logic in the GotoIf does not work…YET


#5

Your logs indicate you are using the version with no $ before [.


#6

After many many attempts I got result…

exten => *2,n,GotoIf($["${IVRONOFF}" = “1”]?:lbl_vdp-outbound_0)

I’m using Freepbx with the latest Asterisk version available. How can a newbie know this by not reading 20 years of asterisk history :wink: ? Thanks for the provide help. It helps to keep people motivated to dive deeper in this stuff.