Retain Incoming Caller ID in Queues

I need help retaining caller id when incoming calls goes into queue and then gets transferred to another queue. When the call comes into the original queue, the dialplan saves it to DB(CALLTRACE/${DEXTEN}). As soon as the call is transferred to another queue, the caller id now the agent’s extension number. I have tried putting into a inherited variable when the call is answered and in the macro-dial-one(ctset). Here is my modified dialplan. This is part of the macro-dial-one and is in the extensions_override_freepbx file.

exten => ctset,1,Set(DB(CALLTRACE/${DEXTEN})=${CALLERID(number):-10:10})
exten => ctset,n,ExecIf($[ "${LEN(${CALLERID(number)})}" = "10" | "${LEN(${CALLERID(number)})}" = "12" ]?Set(DB(CALLTRACE2/${DEXTEN})=${CALLERID(number):-10:10}))
exten => ctset,n,ExecIf($["${LEN(${CALLERID(number)})}"="4"]?Set(DB(CALLTRACE2/${DEXTEN})=${DB(CALLTRACE/${CALLERID(number)})}))
exten => ctset,n,NoOp(Setting CALLTRACE/${DEXTEN}=${CALLERID(number):-10:10})
exten => ctset,n,NoOp(Setting CALLTRACE2/${DEXTEN}=${DB(CALLTRACE/${CALLERID(number)})})
exten => ctset,n,Set(__CEXTEN=${DEXTEN})
exten => ctset,n,ExecIf($[ "${LEN(${CALLERID(number)})}" = "10" | "${LEN(${CALLERID(number)})}" = "12" ]?Set(__OriginalCID=${CALLERID(number):-10:10}))
exten => ctset,n,ExecIf($[ "${LEN(${CALLERID(number)})}" = "10" | "${LEN(${CALLERID(number)})}" = "12" ]?Set(__CALLTRACE=${CALLERID(number):-10:10}))
exten => ctset,n,Return()

I created another dialplan to do a transfer and change the caller id to display as the original incoming CID.

exten => 3328,1,NoOp(Initiated attended transfer)
exten => 3328,n,NoOp(Original CID = ${OriginalCID})
exten => 3328,n,NoOp(CALLTRACE CID = ${CALLTRACE})
exten => 3328,n,NoOp(EXTEN = ${CEXTEN})
exten => 3328,n,Noop(Original CID from DB: ${DB(CALLTRACE2/${CEXTEN})})
exten => 3328,n,Set(CALLERID(num)=${OriginalCID})
exten => 3328,n,ExecIf($[ "${LEN(${CALLERID(num)})}" = "4" & "${LEN(${CEXTEN})}" = "" ]?Set(__CEXTEN=${CALLERID(num)}))
exten => 3328,n,ExecIf($["${OriginalCID}"=""]?Set(CALLERID(num)=${CALLTRACE}))
exten => 3328,n,ExecIf($["${CALLTRACE}"=""]?Set(CALLERID(num)=${DB(CALLTRACE2/${CEXTEN})}))
exten => 3328,n,Dial(${OUT_1}/844NXXXXXX)

I set the variable __OriginalCID here:

exten => _.,1,NoOp(Setting Original CID = ${CALLERID(number):-10:10})
exten => _.,n,Set(__OriginalCID=${CALLERID(number):-10:10})
exten => _.,n,Goto(ext-did-0002,${EXTEN},1)

My main goal is to be able to do an attended transfer and push the customer’s caller id. I’ve tried setting the sendrpid, etc. and it only works when it’s a internal transfer. Attended transfers to external numbers doesn’t work and when the caller is bounced from queue to queue to final agent.