.Call files and CDR

Hi All.
I have an AGI app. that creates a .call file to call a number at a specific time and then run an AGI when the call is answered.
This all works fine, BUT something I have noticed is that the CDR data is output as soon as I answer the call.
I watched the trace of the call and it fires macro-hangup what looks like more than once which is why I suspect that the CDR is being out put.
However, I really wanted to get the CDR data AFTER I hang up not when I answer the call :smile:

Is there a way to output CDR data from an AGI script? p.s. I am using the AMI to get the CDR.

Thanks, Jeremy