Dial plan counter?

This is probably a beginner question, but I haven’t been able to find anything that works the way I expect it to.

I am trying to get a counter that increments with each call that gets placed into the system. Currently what happens is it uses my global variable and will increment that, but it resets the counter to the initial setting with each call(Ex: counter is 1016, call comes in and set to 1017. Second call comes in and it is also 1017.)

Here is the extensions file. Figure there are alot of things I am doing wrong. Let me know what else you need.

[default]
; Comments are good
; This is for when someone calls 1001
exten => 1001,1,Answer()
exten => 1001,2,Playback(hello-world)
exten => 1001,3,Hangup()

; Set a global variable:


; This is used when you try 
; and call 2000 from the console
exten => 2000,1,Dial(SIP/2000,20)
exten => 2000,2,VoiceMail(2000,u)
; For 2001
exten => 2001,1,Dial(SIP/2001,20)
exten => 2001,2,VoiceMail(2000,u)

; For 2002
exten => 2002,1,Dial(SIP/2002)

; For 2003
exten => 2003,1,Dial(SIP/2003)

; For 2005
exten => 2005,1,Dial(SIP/2005)

exten => 2999,1,VoiceMailMain(${CALLERID(num)},s)

[globals]
COUNT=1016

[call-callegra]
exten => 10,1,Answer()

exten => 10,n,Set(COUNT=$[${COUNT} + 1],g)
;exten => 10,n,Wait(10)
exten => 10,n,WaitForSilence(500)
exten => 10,n,SendDTMF(${COUNT})
exten => 10,n,Wait(14)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Wait(5)
exten => 10,n,Hangup()

[from-sip-external]
exten => 2003,1,Dial(SIP/2003)
exten => 2005,1,Dial(SIP/2005)

You need to explicitly reference the global in the target of the set.

However, note that, unless you also use locks, you could lose updates due to race conditions.

Maybe I am not understanding how to reference global variables. I have looked at alot of examples and tried all of them while still getting the same response. Here is one of the changes I recently tried(all in the call-callegra section):

[default]
; Comments are good
; This is for when someone calls 1001
exten => 1001,1,Answer()
exten => 1001,2,Playback(hello-world)
exten => 1001,3,Hangup()

; Set a global variable:


; This is used when you try 
; and call 2000 from the console
exten => 2000,1,Dial(SIP/2000,20)
exten => 2000,2,VoiceMail(2000,u)
; For 2001
exten => 2001,1,Dial(SIP/2001,20)
exten => 2001,2,VoiceMail(2000,u)

; For 2002
exten => 2002,1,Dial(SIP/2002)

; For 2003
exten => 2003,1,Dial(SIP/2003)

; For 2005
exten => 2005,1,Dial(SIP/2005)

exten => 2999,1,VoiceMailMain(${CALLERID(num)},s)

[globals]
COUNT=1016

[call-callegra]
exten => 10,1,Answer()
;exten => 10,n,${INC(COUNT)}
exten => 10,n,Set(NEWCOUNT=$[${COUNT} + 1])
;exten => 10,n,Wait(10)
exten => 10,n,WaitForSilence(500)
exten => 10,n,SendDTMF(${NEWCOUNT})
exten => 10,n,Wait(14)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Playback(hello-world)
exten => 10,n,Wait(5)
exten => 10,n,SetGlobalVar(__COUNT=${NEWCOUNT})
exten => 10,n,Hangup()

[from-sip-external]
exten => 2003,1,Dial(SIP/2003)
exten => 2005,1,Dial(SIP/2005)

And just so you know what I am trying to do. I am using asterisk to place a large number of calls to a call system my company has made. I created a small C# program that connects and copies call files to asterisk in bulk. This part works fine when going to the same extension/DTMF. Right now I want to get the counter to work so that it will not call 1 extension 350 times every minute lol.