Setting CDR variables from within another channel

Hi,

What I want to achieve is to save some additional data to (extended) CDR table in mysql. Particulary, a call comes in through a channel and is passed to a context, where I do something like:

exten => _0ZX.,n,Set(CDR(incodec)=${CHANNEL(audionativeformat)}) exten => _0ZX.,n,Set(CDR(inpeerip)=${CHANNEL(peerip)}) exten => _0ZX.,n,Set(CDR(inrecvip)=${CHANNEL(recvip)}) exten => _0ZX.,n,Set(CDR(from)=${CHANNEL(from)}) exten => _0ZX.,n,Set(CDR(uri)=${CHANNEL(uri)}) exten => _0ZX.,n,Set(CDR(useragent)=${CHANNEL(useragent)})

After that, a Dial is executed in the dialplan:

exten => _0ZX.,n,Dial(SIP/${EXTEN:1}@pbx,40,M(logoutchaninfo))

That’s fine. But, what I want to achieve is to store some data about the outbound channel (that is created with the Dial command), and that I try to do with the macro-logoutchaninfo:

[macro-logoutchaninfo]
exten => s,1,Set(CDR(outcodec)=${CHANNEL(audionativeformat)})
exten => s,n,Set(CDR(outpeerip)=${CHANNEL(peerip)})
exten => s,n,Set(CDR(outrecvip)=${CHANNEL(recvip)})

However, this is obviously not possible because the Set commands executed within the macro are actually executed on another channel.

I would like to have a single CDR entry with info on both inbound and outbound channels.

Any idea or hint would be greatly appreciated.

Thanks,
Nikola