CALLBACK feature. Reading CallCompletion values from database

Hi!!

I’m using asterisk Asterisk 14.2.1

I’m trying to implement the Call Completion Supplementary Services (CallBack) and it works if I’m using a basic config on the phones context:

exten => 7000,1,Dial(SIP/ext7000,20)
same => n,Hangup()

My problem is that I’m using a subrotine to check forward status before dialing the extension.
When I dial the Call Completition code *40 this feature stays on my subrotine and when the phone became idle it jumps directly to that subrotine section and the dial fails:

asterisk*CLI> cc report status
1 Call completion transactions
Core ID Caller Status

73 SIP/ext7010 Caller is attempting to recall
|–>No-Forward@standardextensiondial
|–>SIP/ext7000(CCNR)

Is there a way to get this value SIP/ext7000(CCNR) onto a variable or a way to workaround this?

My subrotine to dial extensions is like that:

[standardextensiondial]
;
;${temp} - FW target
;
;Check if CFW is configured
exten => s,1,Set(temp=${DB(CFW_ALL/${NUMBERTODIAL:7})}) ; Get CFW_ALL key, if not existing, goto next line
same => n,NoOp(CheckCallForward)
same => n,GotoIf(${temp}?:Check-BusyFWD,1)
same => n,NoOp(CallForwardActivated)
same => n,GotoIf($["${temp}"="${CALLERID(num)}"]?No-Forward,1); if cfw target and calling are equal then allow to dial the source extension
same => n,GotoIf($["${temp}"="${VOICEMAILNUMBER}"]?Go-VoiceMail,1)
same => n,Dial(Local/${temp}@phones,240) ; Unconditional forward
same => n,Return

;Check if CFW_BUSY is configured
exten => Check-BusyFWD,1,NoOp(CheckBusyFWD)
same => n,NoOp(CheckCallForwardBusy)
same => n,Set(temp=${DB(CFW_BUSY/${NUMBERTODIAL:7})}) ; Get CFW_BUSY key, if not existing
same => n,GotoIf(${temp}?:Check-noanFWD,1)
same => n,NoOp(Busy CallForwardActivated)
same => n,NoOp(Caller ${CALLERID(num)})
same => n,Dial(${NUMBERTODIAL},240) ; 240sec timeout
same => n,Gotoif($[ “${DIALSTATUS}” = “BUSY” ]?:No-Forward,1)
same => n,GotoIf($["${temp}"="${VOICEMAILNUMBER}"]?Go-VoiceMailBusy,1);if busy and voicemail programmed
same => n,Dial(Local/${temp}@phones,240) ; Busy forward
same => n,Return

;Check if CFW_NOAN is configured
exten => Check-noanFWD,1,NoOp(ChecknoanFWD)
same => n,NoOp(CheckCallForwardNoan)
same => n,Set(temp=${DB(CFW_NOAN/${NUMBERTODIAL:7})}) ; Get CFW_NOAN key, if not existing, goto 105
same => n,GotoIf(${temp}?:No-Forward,1)
same => n,NoOp(noan CallForwardActivated)
same => n,NoOp(Caller ${CALLERID(num)})
same => n,Dial(${NUMBERTODIAL},20) ;dial first the estension then
same => n,GotoIf($["${temp}"="${VOICEMAILNUMBER}"]?Go-VoiceMail,1);if target is voicemail
same => n,Dial(Local/${temp}@phones,240) ; dial Forward on noan target
same => n,Return

;goes to Voicemail CFW_ALL or CFW_NOAN
exten => Go-VoiceMail,1,NoOp(Goes mailbox…)
same => n,VoiceMail(${NUMBERTODIAL:7}@default,u); goes voicemail with unavailable status
same => n,Return

;goes to Voicemail CFW_BUSY
exten => Go-VoiceMailBusy,1,NoOp(Goes mailbox…)
same => n,VoiceMail(${NUMBERTODIAL:7}@default,b); goes voicemail with unavailable status
same => n,Return

; No CFW key so dial the extension
exten => No-Forward,1,NoOp(Dial extension)
same => n,Dial(${NUMBERTODIAL},240) ; 240sec timeout
same => n,Return

[phones]

include => Queues ; allow phones to call queues
include => features

;declare hints
exten => 7000,hint,SIP/ext7000
exten => 7001,hint,SIP/ext7001
exten => 7010,hint,SIP/ext7010

exten => 7000,1,NoOp(a marcar…)
same => n,Set(NUMBERTODIAL=SIP/ext${EXTEN})
same => n,Gosub(standardextensiondial,s,1)
same => n,Hangup

exten => 7001,1,NoOp(a marcar…)
same => n,Set(NUMBERTODIAL=SIP/ext${EXTEN})
same => n,Gosub(standardextensiondial,s,1)
same => n,Hangup

exten => 7010,1,NoOp(a marcar…)
same => n,Set(NUMBERTODIAL=SIP/ext${EXTEN})
same => n,Gosub(standardextensiondial,s,1)
same => n,Hangup

Thanks on advance for your help.

Best Regards,

Jose